loading...

re: Refactoring useState() To useReducer() VIEW POST

FULL DISCUSSION
 

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);
 

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

code of conduct - report abuse