Skip to content
FEE
Frontend Engineering Essentials

[FEE-600] State Management Overview ​

INFO

This category covers how to organize, access, and synchronize the data that drives your UI -- from a single boolean toggle to complex multi-source server data.

Context ​

Modern frontend UIs are functions of underlying data: form inputs, authentication tokens, cached API responses, URL parameters, animation progress. The formula UI = f(state) is easy to write and hard to run. In practice, state arrives from multiple asynchronous sources (user events, network responses, web sockets, browser APIs), must remain consistent across many components, and often needs to survive navigation, tab switches, and offline periods.

The real difficulty is the dependency chain, and the chain exists because state depends on state. A loading spinner depends on a fetch request; the fetch request depends on a URL parameter; the URL parameter depends on a user action; the user action depends on authentication state. When any link in that chain updates incorrectly, the UI becomes inconsistent, and users lose trust.

State Taxonomy ​

Not all state is created equal. Recognizing the kind of state you are dealing with is the first step toward choosing the right tool:

CategoryDescriptionExamplesTypical Tool
Local (UI) StateBelongs to a single componentToggle open/closed, input value, hoveruseState, ref()
Derived StateComputed from other stateFiltered list, total price, full nameuseMemo, computed()
Shared StateNeeded by multiple componentsTheme, locale, shopping cartContext, Zustand, Pinia
Server StateAsync data owned by the backendUser profile, product list, notificationsTanStack Query, SWR
URL StateEncoded in the URLSearch query, pagination, filtersRouter params, useSearchParams
Machine StateFinite, explicit transitionsMulti-step form, auth flow, media playerXState, useReducer

Each category has different ownership, update sources, and lifecycle. Treating server state the same as local UI state, or stuffing everything into a global store, is a common source of over-engineering.

Tools Map to State Types ​

The taxonomy table above already answers "which state, which tool." Most applications use several categories at once: useState for local state, TanStack Query for server data, URL parameters for shareable filters. These tools are orthogonal; none is an advanced version of another.

A global store (Zustand, Pinia, Redux Toolkit) is for client state that several components genuinely share. A state machine (XState) is for flows whose valid transitions can be enumerated. You don't "graduate" from useState to TanStack Query or XState; they solve different problems.

Design Thinking ​

Why State Management Is Hard ​

Three forces make state management uniquely difficult:

  1. Multiple async sources. User interactions, API responses, web socket messages, browser events (resize, online/offline), and timers all produce state updates. These sources operate on different timescales and can arrive in any order.

  2. Consistency across the component tree. When a user logs out, every component showing user-specific data must update. When a product is added to a cart, the header badge, the cart drawer, and the checkout page must all reflect the change. Inconsistency is immediately visible and erodes user trust.

  3. The UI = f(state) contract. Because the UI is a pure function of state, any data-layer bug ends up attributed to the state management layer: a button that should be disabled but is not, stale data shown after navigation, a flash of wrong content during loading. UI predictability is bounded by state-management predictability.

The Over-Engineering Trap ​

A common mistake is reaching for a state-management library too early.

Consider the typical evolution:

  • A developer reads about Redux in a tutorial and adds it to a new project
  • Every piece of state goes into the global store, including form input values and modal visibility
  • The codebase accumulates boilerplate: actions, reducers, selectors, middleware
  • Performance degrades because store subscriptions are coarse-grained: without selectors, unrelated field changes trigger component re-renders
  • The team concludes "state management is hard" when the real problem was unnecessary indirection

The pragmatic approach:

  • Use useState / ref() for component-local state; most state is already component-scoped
  • Use a server-cache library (TanStack Query, SWR) for async data: these libraries handle refetch, invalidation, and optimistic updates that useState can't
  • Only reach for a lightweight store (Zustand, Jotai, Pinia) when client state is genuinely shared across components
  • Reserve state machines (XState) for flows whose valid transitions can be enumerated

This layered approach means most components have zero dependency on external state libraries, making them easier to test, move, and refactor.

Visual ​

State Taxonomy ​

Category Roadmap (FEE-601 through FEE-607) ​

  • FEE-500 Component Architecture & Design Patterns Overview -- state lives inside components; architecture determines where state belongs
  • FEE-502 Reactive State & Signals -- the underlying mechanism that makes state changes visible to the UI

References ​