For this post I will be going over on updating state object like with the help of useState hook in functional components of ReactJS:
The state object already has value for property defined. Now we want to update the property os to iOS 12
while preserving the state of name property. Here’s how to do it:
What if we have a list/array of objects in our device state like:
Now before we update we need to do a quick lookup, here’s how we update the state when we find the item we want to update:
That is it. Your state is now updated. This can be useful when we are updating list of objects and performing CRUD operations on the list while updating the db in the backend. Enjoy!