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.
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.
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.
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.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.