Home > Enterprise >  React, update/reset nested state
React, update/reset nested state

Time:04-20

i need to reset a state. I have:

console.log(this.state["status"].toBeDeleted) //0|22|15

I need to empty this.state["status"].toBeDeleted. I have tried with this.setState but I didn't managed.

Thanks

CodePudding user response:

You might be running into this issue because toBeDeleted is a nested property. You can attempt the setState as following, which should work:

this.setState({
   ...this.state,
   status: {
      ...this.state["status"]
      toBeDeleted: undefined
   }
})

Hope this helps!

  • Related