我有一種方法叫做devCreateSteps我想使用狀態,但它會拋出一個錯誤說;在方法中使用狀態 - 反應
Uncaught TypeError: Cannot read property 'isTemplateUsed' of undefined
這是我的代碼片段;
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 />),
}];
問題是我不能在devCreateSteps
什麼是使用狀態,其發送的道具以正確的方式使用
isTemplateUsed={this.state.isTemplateUsed}
呢?
你有沒有反應控制檯。如果是,請告訴我你在'state'中對'StepOne'組件有什麼作用 – Gardezi
它在轉到StepOne組件之前實際上會引發錯誤。我有一個控制檯來查看StepOne中的狀態,但它永遠不會去那裏。 –
但這是我在StepOne的狀態; 構造函數(道具){ super(道具); this.state = { isTemplateUsed:this.props.isTemplateUsed }; } –