DEV Community


Discussion on: My 5 cents about React Hooks

guilhermetoti profile image
Guilherme Toti Author

True, it replaces the whole state, but I do prefer to have an object on state instead N variables, (depending the case), but I think this is personal preferences.
When I set states with objects, I usually update it like (e.g):

setData(data => ({, someUpdate: “ok” });

This way I get the current state value, add it to my object, and update what I want on it... keeping it immutable.