报错内容如下:
看看是不是在componentDidUpdate钩子函数中调用了this.setState()方法,导致componentDidUpdate陷入死循环
最初的代码如下:
componentDidUpdate(preProps) {
this.setState({
start: this.props.start
end:this.props.end
})
}
解决:在setState前判断之前的props中的value和当前props对应的value是否相等不等的话再调用setState
componentDidUpdate(preProps) {
if (preProps.start!= this.props.start || preProps.end != this.props.end) {
this.setState({
start: this.props.start
end:this.props.end
})
}
}