2
我不知道這是否修改我終極版狀態:我在這裏修改我的Redux狀態嗎?
var tempArray = this.props.currentView.someArray;
tempArray.push(this.state.inputField);
第一行是複製的內容,或者這是創建一個實際的參考對象的道具?
我不知道這是否修改我終極版狀態:我在這裏修改我的Redux狀態嗎?
var tempArray = this.props.currentView.someArray;
tempArray.push(this.state.inputField);
第一行是複製的內容,或者這是創建一個實際的參考對象的道具?
var tempArray = this.props.currentView.someArray;
會使tempArray引用數組。
tempArray.push()
修改參考。因此,它會修改this.props.currentView.someArray
。
如果你不想修改你的狀態,你可以做。
var tempArray = this.props.currentView.someArray.slice();
切片不會修改原始數組並調用它沒有參數返回原始數組的副本。
修改後,這tempArray
會對this.props.currentView.someArray
驚人的沒有效果,謝謝! –