DEV Community

Discussion on: Refactoring useState() To useReducer()

Collapse
 
shiftyp profile image
Ryan Kahn (he/him)

Hi! I like the simplicity of the reducer in this case, but I would rename the references like so to make it more readable for me (the achilles heel of reducers imho)

const initialFields = {
   // ...
}

function reduceFields(currentFields, { field, value } ) {
  return { ...currentFields, [field]: value };
}

const [fields, updateField] = useReducer(reduceFields, initialFields);
Collapse
 
m0nica profile image
Monica Powell

Thanks for the naming suggestion! I'm always trying to figure out how to name things better.