由于子组件中使用了componentWillReceiveProps,每次在父组件中使用setState时,都会执行componentWillReceiveProps
解决办法:在componentWillReceiveProps中进行判断,如果不满足条件及时return即可解决
// 子组件
componentWillReceiveProps() {
if (this.state.selectItem === this.props.isDefaultChoiseUnlimited) {
return;
}
console.log(this.state.selectItem, this.props.isDefaultChoiseUnlimited);
this.setState({ selectItem: this.props.isDefaultChoiseUnlimited });
}
网友评论