reactjs - 将 props 从父组件传递给子组件并以 redux 形式使用 connect
问题描述
TypeError:无法读取未定义的属性“状态”
但是在父组件上,我将状态作为道具传递。为什么我无法在这里获得 this.props.status ?
class App extends Component{
render(){
return (
<div>
<childComponent
status={true}
/>
<div>
)
}
}
ChildComponent.js
class childComponent extends Component{
render(){
console.log("props passed", this.props.status) // getting true
return(
)
}
}
export default reduxForm({
form: 'wizard',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
enableReinitialize: this.props.status ? true : false, // error happening
})(
connect(
mapStateToProps,
mapDispatchToProps
)(childComponent)
);
与此问题相关的问题
解决方案
您只能访问班级this.props
内部childComponent
。外部将无法访问它们。
如果您需要enableReinitialize
动态更改参数或任何其他参数,也许此链接会对您有所帮助。
https://github.com/erikras/redux-form/issues/603#issuecomment-239543148
推荐阅读
- spring-boot - 在 CORS spring security + webFlux 中启用通配符
- javascript - 如何有效地将数组中的每个值与其他值进行比较?
- javascript - 如何使用 ReactJS 避免递归方法中的许多重新渲染
- mysql - PowerApps MySl - 下拉问题
- reactjs - 从 HashRouter 更改为 browserRouter 后,React router 4 路由停止工作
- r - R中不同行中相同字符串的总和
- php - 在父子类别中显示父子类别的其他子类别
- python - 对齐可迭代:错误“字符串无法从手动字段规范切换到自动字段编号”
- facebook - 使用 Fb SDK 使用 Facebook 进行 Cognito 登录
- typescript - 如何从 index.d.ts 中的@types 导入接口?