DEV Community

Cover image for How to Easily update an Object that's in state in React
Noel Ethan Chiwamba
Noel Ethan Chiwamba

Posted on • Originally published at dev.to

How to Easily update an Object that's in state in React

Liquid syntax error: 'raw' tag was never closed

Top comments (4)

Collapse
 
vishal8888a8 profile image
vishal giri

Good one but I think spread operator is the best way to update react state in such case

Collapse
 
noel_ethan profile image
Noel Ethan Chiwamba

I understand there are a couple of ways to achieve the same, I just wanted to make it basic. Thank You.

Collapse
 
tealover418 profile image
Stijn de Ligt

You should look into useReducer. It's an alternative to useState but for more complex objects like what you have here.

Collapse
 
noel_ethan profile image
Noel Ethan Chiwamba

Thank you. However I just wanted to keep it basic, but i will consider useReducer too as a Scale up for the article.