How do you keep your UI in sync with your data? State management is the layer between your API and your components — and choosing the wrong tool for the job is the most common source of React complexity. Here is everything you need to know about the eight major state management patterns and when to use each one.
FrontendX Engineering · System Design Series
State management is the art of keeping your UI in sync with your data. As applications grow, the naive approach — "put everything in a React component's useState" — breaks down. Data needs to be shared between components, persisted across routes, cached from the server, and updated in real time.
This guide covers eight state management patterns, from the built-in React primitives to purpose-built libraries for server state, atomic state, and state machines. We will look at how each one works, when it shines, and the tradeoffs you accept when you choose it.
The most important insight: there is no single best tool. The right choice depends on what kind of state you are managing. Before we talk about tools, we need to talk about categories.
Every piece of state in a frontend application falls into one of three buckets: local state (belongs to one component), global state (shared across many components), and server state (lives on the server, cached on the client). The mistake most developers make is reaching for global state management for everything, including server state.
Server state has different concerns — caching, deduplication, background refetching, optimistic updates — that global state libraries handle poorly. This is why TanStack Query exists.
| Category | Description | Examples | Tools |
|---|---|---|---|
| Local State | Belongs to one component or a small tree | Form inputs, toggles, accordions, pagination | useState, useReducer, Context |
| Global State | Shared across unrelated components | Auth user, theme, cart, UI preferences | Zustand, Redux, Jotai, XState |
| Server State | Lives on server, cached on client | Product listings, user profiles, notifications | TanStack Query, SWR, Apollo |
useState is the foundation. Every other pattern is built on top of it or replaces it for a specific reason. It is the simplest form of state — a value and a setter — and it belongs entirely to the component that declares it.
When your state logic gets complex — multiple related values that change together, or transitions that depend on previous state — useReducer gives you a more predictable structure. State changes go through a central reducer function, making transitions explicit and testable.
useState for simple independent values: form fields, toggles, counters.useReducer for state with multiple related transitions: multi-step forms, undo/redo, complex UI interactions.useReducer adds boilerplate but brings predictability and testability.useReducer is essentially useState with a dispatch function. It does not provide global access — it is still local state. The advantage is testability (the reducer is a pure function) and predictability (state changes go through a central function). If your local state is simple, start with useState.React Context lets you pass data through the component tree without manually threading props. It is not a state management solution — it is a dependency injection mechanism. You still need useState or useReducer somewhere to hold the actual state; Context just makes that state accessible anywhere in the tree.
Zustand is a tiny (~1 KB) state management library that gives you a global store with subscriptions. You create a store with a single function, and components subscribe to slices of that store via selectors. Only the components whose selected value changes re-render.
useStore anywhere.Redux is the oldest and most established global state library in the React ecosystem. It enforces a strict unidirectional data flow: components dispatch actions, reducers compute the new state, and subscribers re-render. Redux Toolkit (RTK) has dramatically reduced the boilerplate that gave Redux a bad reputation.
TanStack Query (formerly React Query) solves a different problem than the libraries above. It manages the state that lives on your server but is cached on the client. This is not "global state" — it is a cache layer with automatic background synchronization, request deduplication, and optimistic updates.
staleTime vs gcTime vs refetch intervals is essential for correct usage.Jotai takes a fundamentally different approach. Instead of a single global store, you create many small, independent "atoms" that can be composed together. Atoms are like useState hooks that live outside the component tree but can be imported and used anywhere.
URL state is often overlooked. The URL is a powerful state container — it is persistent (bookmarkable), shareable, and survives page refreshes. Using search params and hash fragments for state is the most resilient form of persistence.
XState brings formal state machine theory to frontend state management. Instead of boolean flags scattered across components (isLoading, isError, isSuccess), you model the entire lifecycle of a piece of functionality as a finite state machine.
useEffect hooks.useEffect that handles loading, error, retry, cancel, and polling, you need a state machine. XState makes complex flows visible and testable in a way that imperative code cannot match.Here is how the eight patterns stack up across the dimensions that matter most in production:
| Dimension | useState | Context | Zustand | Redux | TQ | Jotai | URL | XState |
|---|---|---|---|---|---|---|---|---|
| Bundle size | 0 KB | 0 KB | ~1 KB | ~11 KB | ~13 KB | ~4 KB | 0 KB | ~15 KB |
| Boilerplate | Minimal | Medium | Low | High | Low | Low | Minimal | Medium |
| Learning curve | Trivial | Easy | Easy | Steep | Moderate | Moderate | Trivial | Steep |
| Re-render control | Built-in | None | Selectors | Selectors | Built-in | Granular | N/A | Subscriptions |
| Server state | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
| DevTools | React DevTools | React DevTools | Zustand DevTools | Redux DevTools | RQ DevTools | Jotai DevTools | Browser URL | Stately Viz |
| Middleware | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
Zero KB, zero boilerplate, trivial to learn. Perfect for local component state. Falls apart when state needs to be shared.
Also zero KB, but no re-render control. Good for low-frequency reads (theme, auth). Bad for high-frequency updates.
~1 KB, selector-based subscriptions, no providers. The best general-purpose global state library for most apps.
~4 KB, tree-shakeable atoms with derived state. Brilliant for complex computations, overkill for simple CRUD.
~11 KB, steep learning curve, unmatched DevTools. Choose when you need team-scale conventions and middleware.
~13 KB, but replaces hundreds of lines of custom fetching logic. Automatic caching, dedup, background refetching.
Zero KB, persistent, bookmarkable. Perfect for filters, pagination, and search. Not for complex data.
~15 KB, paradigm shift for complex flows. Makes impossible-to-debug useEffect spaghetti visible and testable.
Choosing a state management approach is about matching the category of state to the right tool. Here is a decision framework:
| Scenario | Recommended | Why |
|---|---|---|
| Form input / toggle | useState | Belongs to one component. Zero overhead. |
| Theme / locale / auth | Context | Low-frequency reads. Built-in. No extra deps. |
| Shopping cart / UI prefs | Zustand | Subscriptions, selectors, 1 KB. Just right. |
| API data (products, users) | TanStack Query | Caching, dedup, background refetch. Essential. |
| Filters / pagination / search | URL state | Bookmarkable, shareable, persistent. |
| Multi-step checkout flow | XState | State machine prevents illegal transitions. |
| Complex derived calculations | Jotai | Derived atoms handle dependency graphs. |
| Large team / enterprise | Redux Toolkit | Conventions, middleware, time-travel debugging. |
State management is not a one-size-fits-all decision. The best approach depends on the category of state you are managing. Here is what to remember:
useState. Most state starts local. Only abstract when you feel the pain of prop drilling or re-render issues.useEffect, you need a state machine.For a typical React application in 2025:
useState / useReducerThis combination covers 95% of state needs with minimal boilerplate and excellent developer experience.