React State Management: Redux, Context or Server State?

React State Management: Redux, Context or Server State?

Most state is server state. Once you separate it, choosing between Redux and Context becomes easy.

State management debates usually mix up three different kinds of state. Separate them and the tool choice mostly makes itself.

Three kinds of state

  • Server state: data that lives in your API, like products and orders.
  • Global UI state: things many components share, like the signed-in user or a cart.
  • Local UI state: an open modal, a form field, a selected tab.

Server state: use a data-fetching library

Caching, refetching and loading states are solved problems. TanStack Query or RTK Query handle them better than hand-written reducers, and they remove most of what people used Redux for.

Local state: keep it local

useState and useReducer inside the component that owns the state. Lifting state too early is the most common cause of unnecessary re-renders.

Global UI state: Context or Redux Toolkit

Context is perfect for values that change rarely, like theme or the current user. For complex, frequently updated client state with many writers, Redux Toolkit gives you predictable updates and great dev tools.

My default

  1. TanStack Query or RTK Query for API data.
  2. useState for local UI.
  3. Context for rarely changing globals.
  4. Redux Toolkit only when client state gets genuinely complex.

More on this topic

Photography
3D Models
Development
Illustrations
Fashion
Digital Art
Packaging
Motion
Illustrations
Video Production
Photography
3D Models
Development
Illustrations
Fashion