How to update nested state properties in React

后端 未结 26 2449
野趣味
野趣味 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
    2020-11-21 07:32

    I found this to work for me, having a project form in my case where for example you have an id, and a name and I'd rather maintain state for a nested project.

    return (
      

    Project Details

    this.setState({ project: {...this.state.project, id: event.target.value}})} /> this.setState({ project: {...this.state.project, name: event.target.value}})} />
    )

    Let me know!

提交回复
热议问题