DEV Community


Discussion on: Refactoring useState() To useReducer()

shiftyp profile image
Ryan Lynch (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);
m0nica profile image
Monica Powell Author

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