useReducer Basics & Action Patterns
Learn useReducer: state + reducer(state, action) → next state. Use clear actions (type, payload) to handle multi-field updates.
Why useReducer?
Goal: Use useReducer to manage updates with a single reducer function. It is handy when several fields change together.
- State object
- Actions: type + payload
- Pure reducer(state, action)
Reducer anatomy
Reducer takes the current state and an action, returns the next state. Keep it pure (no side effects). Use small action types like INCREMENT, RESET, or UPDATE_FIELD.
All lessons in this course
- Context Basics & Avoiding Prop Drilling
- useReducer Basics & Action Patterns
- Context + Reducer: Simple State Containers