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. 😃
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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. 😃