Search code examples
javascriptreactjsecmascript-6setstate

React, update/reset nested state


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


Solution

  • 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!