DEV Community

Discussion on: React hooks - working with state (objects)

Collapse
 
lexlohr profile image
Alex Lohr

I think useReducer would be a better fit for more complex states than manual mangling objects. However, I would only use it if it truly reflects the actual complexity of the use case, which is not really broken down into less complex states.

Thread Thread
 
joelynn profile image
Joseph Lynn • Edited

I agree that useReducer would be beneficial for complex state. However we are adding a static object in this case. We are not mangling the object state, we are copying the current state and adding a new object (which is exactly what useReducer would do but based on an action). It would not work to have separate state for id and name in this case - as they work together and identify the object.