【发布时间】:2017-09-13 07:09:20
【问题描述】:
我有一个名为 devCreateSteps 的方法,我想在其中使用状态,但它会引发错误提示;
未捕获的类型错误:无法读取未定义的属性“isTemplateUsed”
这是我的代码的 sn-p;
constructor() {
super();
this.state = {
modalVisible: false,
tableLoading: false,
modalHeader: "",
isTemplateUsed: false
};
}
devCreateSteps = [{
title: 'Info',
content: (<StepOne isTemplateUsed={this.state.isTemplateUsed} />),
}, {
title: 'Device',
content: (<StepTwo />),
}, {
title: 'Location',
content: (<StepThree />),
},
{
title: 'Properties',
content: (<StepFour />),
},
{
title: 'Controls',
content: (<StepFive />),
},
{
title: 'Summary',
content: (<StepFinal />),
}];
问题是我不能用
isTemplateUsed={this.state.isTemplateUsed}
这在 devCreateSteps
使用 state 作为 props 发送的正确方法是什么?
【问题讨论】:
-
你有反应控制台吗?如果是,请告诉我
stateforStepOne组件中有什么 -
它实际上在转到 StepOne 组件之前抛出了错误。我有一个控制台可以查看 StepOne 中的状态,但它永远不会去那里。
-
但这是我在 StepOne 中的状态;构造函数(道具){ 超级(道具); this.state = { isTemplateUsed: this.props.isTemplateUsed }; }
-
如果
state也是一个类道具,这将起作用,而不是在构造函数中完成。
标签: reactjs