Use a reducer when form behavior becomes more complex.
Section: Forms and Event Patterns
Complex form with useReducer
tsx
tsx
function formReducer(state: FormState, action: FormAction): FormState {
switch (action.type) {
case 'change':
return { ...state, [action.name]: action.value };
case 'reset':
return action.initial;
default:
return state;
}
}Explanation
Reducers become easier to scale than ad hoc state updates for complex forms.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Forms and Event Patterns