React state tip: Group related state into a single useState call (via an object)
React state tip: Group related state into a single useState call (via an object).
Benefits:
✅ Less code
✅ Better readability
✅ Groups related items
✅ Clearer mental model
✅ Easy to send to the server (assuming the object shape matches the API's desired shape)
#react

Note: I avoid declaring nested objects in state. Why? Because object spread does a shallow clone.
So, if there's a nested object, I tend to prefer to put that in a separate state declaration. Doing so avoids being bit by forgetting that object spread does a shallow clone.