Skip to content
ClapelloNotes by Barath
ReactCh 12 · 1/6
Beginner4 min readUpdated

React / 64

Do you need Redux?

TL;DR

Props, Context or Redux? Pick by how many components need the data and how often it changes. Most state never needs Redux.

Give state the smallest home that works

Most state is local, and should stay that way. Move it somewhere bigger only when you have a reason.

  1. 1 · used by one component

    useState / useReducer

    a dropdown's open flag, an input's text
  2. 2 · used by a parent + a few children

    Lift state up, pass props

    a filter shared by a list and its toolbar
  3. 3 · used by many components, changes rarely

    Context

    theme, logged-in user, language
  4. 4 · used by many components, changes often

    Redux Toolkit (or Zustand)

    a cart, an editor document, complex filters

a different kind of state

Data that lives on a server

Menus, orders, profiles: use RTK Query or TanStack Query. They fetch, cache and refresh it for you.

Start at the top. Move down only when the data is needed in more places, or changes in more complicated ways.

useContext vs Redux

Both let far-apart components share data, so people often compare them. They solve different problems.

Context (useContext)Redux Toolkit
What it isA way to pass a value down the treeA store that holds state and controls how it changes
Comes with React?YesNo: @reduxjs/toolkit + react-redux
Where state livesStill in a useState / useReducer above the providerIn the store, outside your components
When the value changesEvery component reading the context re-rendersOnly components whose selected piece changed re-render
Changing the dataWhatever setter you pass downOnly by dispatching actions to reducers
DebuggingReact DevToolsRedux DevTools: every action, every diff, time travel
Async logicWrite it yourselfThunks and RTK Query built in
SetupA few linesA slice, a store and a Provider (still small with Toolkit)

So Context is a transport, not a state manager. Pair it with useState for data that's read in many places but changes rarely: theme, language, the logged-in user.

Signs you need Redux

  • Many components, far apart, read and change the same data (a cart, a document editor, a set of filters).
  • The update logic is complex: several kinds of change to the same data, each with rules.
  • You want to answer "what changed, and why?" by looking at a log of actions.
  • A bigger team benefits from one predictable pattern for every feature.

Signs you don't

  • The data is used by one component or one small branch: keep it in useState.
  • It's mostly data from a server: use RTK Query (part of Redux Toolkit) or TanStack Query, which handle loading, caching and refetching for you.
  • The app is small. Adding Redux early costs more than it saves.

Gotchas

Recall

Can you answer these?

0/4

Answer out loud (or in your head) before you tap. That's what makes it stick.

Saved on this device only. No login.