【发布时间】:2017-05-17 07:35:58
【问题描述】:
大家好,我是新来的反应 我正在使用从父组件的状态传递属性的反应组件,我不确定为什么每当我从父组件触发和事件时都会收到未定义的属性错误
您可以在这里访问代码@https://codepen.io/private_ryan/pen/RVBdpO?editors=0011#live-view显示控制台并点击编辑按钮
SampleTable 组件
constructor(props, context) {
super(props);
this.state = { UPD:[] };
}
updateRow(x) {
var array = this.state.TRs;
var index = array.findIndex(e => e.id == x);
this.setState({
UPD: this.state.TRs[index]
});
}
render() {
return (<AddFormData onAdd={ this.onAddForm }
upd={ this.state.UPD }
updcan={ this.cancelUpd }
propUpd= { this.propcessUpd } />
<button onClick={ this.updateRow} value={ some.id } >click me</button>
);
}
AddFormData 组件
constructor(props) {
super(props);
this.state = { textName: '', textArea: '' };
}
componentWillReceiveProps(){
console.log( this.props ) // undefined no props when first click
// set the state here
}
【问题讨论】:
标签: javascript reactjs