React Hooks Patterns/Complex form with useReducer

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
Controlled form state
Manage a form object with useState.
OpenIn sheettsxsame section
Debounced input value
Delay reactions to rapidly changing values.
OpenIn sheettsxsame section
Basic custom hook
Extract reusable stateful logic into a function.
OpenIn sheettsx2 tag match
Track previous value
Store the previous render’s value.
OpenIn sheettsx2 tag match
Fetch with AbortController
Cancel stale requests on dependency change.
OpenIn sheettsx2 tag match
Custom hook with options object
Prefer options objects for extensible APIs.
OpenIn sheettsx2 tag match