How to update nested state properties in React

后端 未结 26 1977
野趣味
野趣味 2020-11-21 06:35

I\'m trying to organize my state by using nested property like this:

this.state = {
   someProperty: {
      flag:true
   }
}

But updating

26条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 07:28

    To write it in one line

    this.setState({ someProperty: { ...this.state.someProperty, flag: false} });
    

提交回复
热议问题