我很困惑我從我的代碼中得到什麼。我有以下幾種應該註銷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反正引用了相關部分。 –