Skip to content
Learn Netverks

Lesson

Step 28/36 78% through track

usereducer-intro

useReducer for complex state

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~1 min
Level
intermediate

This lesson

An orientation to the React track—how the playground works, vocabulary, and what you will build next.

You need a clear map of the React track so hooks, state, and tooling do not feel like magic.

You will apply useReducer for complex state in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal. Also read the interview prep blocks.

After solid JavaScript—and ideally TypeScript—before starting the react track.

When state updates involve multiple fields, branching logic, or action history, useReducer centralizes transitions in a pure reducer function—similar to Redux without the boilerplate of a global store.

Shape

const [state, dispatch] = React.useReducer(reducer, initialState);
dispatch({ type: 'increment' });

Reducer rules

  • Must be pure: no fetch, no mutation of arguments
  • Return the next state object (or previous state if nothing changes)
  • Use action types (often discriminated unions in TypeScript) for clarity

useState vs useReducer

Stick with useState for simple toggles and strings. Reach for useReducer when the next state depends on a matrix of prior state + action, or when multiple child handlers dispatch the same actions.

Self-check

  1. Why must reducers avoid side effects?
  2. What does dispatch return?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • useReducer vs useState?
  • Action shape?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump