Reactjs componentDidUpdate()无限循环
当我尝试设置状态时,我收到componentDidUpdate的错误消息,我不知道为什么Reactjs componentDidUpdate()无限循环,reactjs,Reactjs,当我尝试设置状态时,我收到componentDidUpdate的错误消息,我不知道为什么 componentDidUpdate() { if(this.props.isLoadingDept===false && this.props.isLoadingEmpStatus===false && this.props.isLoadingGroup===false && this.props.isLoadingEmpDesig===fals
componentDidUpdate() {
if(this.props.isLoadingDept===false && this.props.isLoadingEmpStatus===false
&& this.props.isLoadingGroup===false && this.props.isLoadingEmpDesig===false){
this.setState({
button:false
})
console.log('UPDATE')
}
}
当该语句为true时,控制台日志值只记录一次,因此我不确定它是如何循环的以及为什么循环的。您可以添加另一个条件来检查状态中的按钮是否已为false,以防止无限循环
if(this.props.isLoadingDept===false && this.props.isLoadingEmpStatus===false
&& this.props.isLoadingGroup===false && this.props.isLoadingEmpDesig===false && this.state.button !== false)
因为一旦你更新了状态,componentdiddupdate
将被调用,并且你在条件中使用的道具没有改变