【发布时间】:2018-12-18 19:17:43
【问题描述】:
为什么 this.setState 不起作用。
constructor(props) {
super(props);
this.state ={
obj: [],
}
}
,
componentDidUpdate(prevProps){
const { obj } = this.props;
this.setState({obj});
}
}
【问题讨论】:
-
尝试控制台日志
this.props.siteDataState -
永远不要在
componentDidUpdate中无条件使用setState。 -
没有道具
siteDataState
标签: javascript reactjs setstate