Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading