【发布时间】:2018-11-09 05:33:05
【问题描述】:
尝试更新 this.state 中数组的一个元素时出现(预期的)错误,但看不到哪里出错了。我是否需要创建一个临时数组更新,然后将整个数组分配回状态
这基本上就是我所拥有的
this.state = { array: ['a', 'b', 'c'] };
onBack() {
this.setState({
array[2]: 'something'
});
}
【问题讨论】:
-
Do I need to create a temporary array update that, then assign the whole array back to the state是 -
@DragoşPaulMarinescu 是正确的,这种方法是最好的方法!
标签: arrays reactjs react-native state native