How to update nested state properties in React

后端 未结 26 2044
野趣味
野趣味 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条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 07:25

    const newState = Object.assign({}, this.state);
    newState.property.nestedProperty = "new value";
    this.setState(newState);
    

提交回复
热议问题