How to update nested state properties in React

后端 未结 26 2444
野趣味
野趣味 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:18

    This is clearly not the right or best way to do, however it is cleaner to my view:

    this.state.hugeNestedObject = hugeNestedObject; 
    this.state.anotherHugeNestedObject = anotherHugeNestedObject; 
    
    this.setState({})
    

    However, React itself should iterate thought nested objects and update state and DOM accordingly which is not there yet.

提交回复
热议问题