reactjs - React Redux Props 在变量赋值期间未定义
问题描述
为什么当我将道具分配给 JSX 变量时,它输出为未定义?这是正常的吗?或者我的程序中是否有其他代码会导致此问题?
const { foo } = this.props;
console.log(this.props);
console.log(foo);
class Library extends Component {
componentDidMount() {
M.AutoInit();
}
render() {
const { foo } = this.props;
console.log(this.props);
console.log(foo);
return <div className="container"></div>;
}
}
const mapStateToProps = state => {
return {
cred: state.cred.tabs
};
};
解决方案
您正试图从foo
. this.props
但根据您的日志,this.props
似乎不包含任何foo
属性。
推荐阅读
- regex - PowerShell - 用于更改多值字段中的分隔符的正则表达式
- azure-application-insights - Visual Studio App Center - 按时间查找诊断日志
- bash - 如何访问用户主目录
- android - 安卓。活动不是从服务开始的
- linux - 使用 ansible playbook 修改 sshd_config 中的 AllowGroups
- java - java比较逗号分隔的字符串
- python - 欧拉计划问题 #1 - 没有得到正确的答案
- node.js - 单击基于 $eval 的 div 会引发 div click 不是 puppeteer 中的功能
- scala - 如果文件不存在,akka http 路由 HttpEntity.fromFile 返回 403
- javascript - 本地主机上的 CSV 文件:如何使用 javascript 动态编辑 csv 文件?