Skip to main content

Reducers visual mental model

A reducer turns current state + action โ†’ next state.

Reducer transition model
Current state

the existing snapshot

Action

describes what happened

reducer(state, action)
Next state

a new snapshot React can render from

Actions describe events, reducers decide transitionsโ€‹

Separate intent from transition logic
Action

{'{ type: "itemAdded", item }'} says what happened.

Reducer

decides how that event changes the state model.

Reducers stay pureโ€‹

Reducer boundary
Inside reducer

calculate next state ยท validate transitions ยท update immutable structures

Outside reducer

network calls ยท analytics ยท timers ยท DOM APIs ยท random external effects

When a reducer helpsโ€‹

Does this state need a reducer?
One or two simple independent values?useState is often clearer
Many related transitions?Reducer can centralize them
Transitions are naturally event/action driven?Reducer is a strong fit
Need transition logic tested independently?Reducer helps
Problem is remote caching or subscription granularity?Reducer alone is not the solution

Reducer + Contextโ€‹

Shared feature state without one giant global store
Feature Provider

owns useReducer

State Context

read current feature state

Dispatch Context

send actions to the owner

Feature UI A
Feature UI B
Feature UI C

The debugging advantageโ€‹

Trace behavior as events and transitions
User / system event
Reducer transition
Next state
UI renders from state

This makes it easier to ask: what action happened, what state existed, and what transition produced the result?

Continue with useReducer and Reducer Design and Reducer with Context for implementation details, TypeScript patterns, and production architecture.