我正在使用React(14.2)和Redux。除了当我在update上分配一个动作时,我有一切设置和工作,发生递归循环。React Redux在更新时发送导致递归错误
componentWillMount() {
const { wizardActions, valid, errors } = this.props
wizardActions.setPropState({valid: valid, errors: errors})
}
componentWillUpdate(nextProps) {
const { wizardActions } = this.props
console.log('NP', nextProps)
//*** IF I UNCOMMENT THE FOLLWOING LINES THE APP GOES INTO AN INFINTIE
// RECURSION LOOP...
/*if(this.props !== nextProps) {
wizardActions.setPropState({valid: nextProps.valid, errors: nextProps.errors})
}*/
}
如何在当前组件的道具更改时更新Redux状态?我也在componentWillReceiveProps()
中试过这个,它也做了同样的事情。
TIA!
使用'if'语句?当然,你只想在具有特定情况的更新后调度,比如'this.props!== nextProps' – azium
添加了if语句,但仍然是相同的行为 –
哦,它不能是* exact * if语句,因为对象引用是总是不同的..这将永远评估为真。你必须比较你想成为新的道具内的特定值。 – azium