我有一个2D数组,我需要在componentWillReceiveProps中更新它,但它没有更新。
这是我的州;
this.state={
conditionRaw:[[]]
}
这是componentWillReceiveProps方法;
componentWillReceiveProps(nextProps){
let rules = {conditionRaw:[[]]};
if (nextProps.rootObject._id !== ""){
rules["conditionRaw"] = nextProps.rootObject.conditionRaw
this.setState({conditionRaw: rules.conditionRaw})
console.log("DENEMEBİRLKİ", this.state.conditionRaw)
}
}
我的nextProps已经填满,但我认为我在setState失败了。
答案 0 :(得分:1)
您的控制台日志:
console.log("DENEMEBİRLKİ", this.state.conditionRaw)
可能会产生误导,因为setState()
是异步的。试试这个:
this.setState({conditionRaw: rules.conditionRaw}, () => {console.log(this.state.conditionRaw);});