DEV Community

Discussion on: Using React useState with an object

Collapse
 
chrisczopp profile image
chris-czopp

useState() isn't meant to manage non-primitive state. It works, however it can behave weirdly with objects as they are mutable. As a matter of fact, I encountered the issue in one of my side projects which led me to React's docs where I found out the preferred way (reactjs.org/docs/hooks-reference.h...) - useReducer(). Just recently I used it to handle state of a dynamic form list and it really is more reliable and maintainable. 😃