我很困惑我从我的代码中得到什么。我有以下几种应该注销data.points
,然后将this.state.points
设置为data.points
,然后注销this.state.points
,但是当它将它们注销时它们不相等。这是我正在使用的确切代码,所以我确信它是输出的。我可能忽略了一些东西,但是我花了过去的时间阅读并注销了这些代码,但我仍然无法弄清楚。这里是我运行代码:状态没有正确设置 - 反应本机
console.log(data.points);
if (!this.state.hasPressed) {
this.setState({points: data.points})
console.log('in not hasPressed if');
}
console.log(this.state.points);
但是在Chrome远程调试我得到这个:
["114556548393525038426"]
in not hasPressed if
[]
可能想在[docs](https://facebook.github.io/react/docs/react-component.html#setstate)上采取一些措施。 –
TL; DR但我可能应该 – pudility
啊@Val反正引用了相关部分。 –