diagram.mmd — flowchart
State Management Flow flowchart diagram

State management flow describes the path that data takes from user interaction through business logic to UI update in a frontend application, typically following a unidirectional data flow pattern.

Unidirectional data flow — popularized by Flux and adopted by Redux, Vuex, Pinia, and Zustand — was designed to solve a specific problem: in two-way data binding systems, it becomes difficult to trace which component changed which piece of state, leading to cascading updates and hard-to-debug bugs. By enforcing that data flows in one direction, every state change has a predictable, traceable path.

The canonical flow starts with a user interaction (a button click, form input, or timer event). The component dispatches an action — a plain object describing what happened ({ type: 'ADD_ITEM', payload: { id: 1 } }). Actions are processed by a reducer (in Redux-style stores) or a mutation (in Vuex/Pinia), a pure function that takes the current state and the action and returns the next state. The store holds this computed state and notifies all subscribed components.

Components that read from the store via selectors or computed properties receive the new state and re-render only if their specific slice changed. This subscription model is what makes fine-grained reactivity possible: a cart component re-renders when cart items change, but a navigation component does not. See Vue Reactivity System for how Vue implements this tracking automatically, and React Rendering Lifecycle for how React handles re-render scheduling.

Async operations — API calls, timers, WebSocket messages — are handled in middleware (Redux Thunk, Redux Saga) or actions (Pinia, Vuex) before dispatching to the reducer. The result of the async call becomes an action payload, re-entering the synchronous flow.

For developers, understanding this flow explains why direct state mutation (outside the store) breaks change detection and why immutability is central to Redux's design.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

Unidirectional state management flow is a pattern where data moves in a single direction: user interaction dispatches an action, a reducer or mutation produces a new state from that action, the store holds the new state, and subscribed components re-render. Because every change passes through this predictable loop, state transitions are traceable and debuggable.
A Redux action is a plain object with a `type` field describing what happened. It is dispatched to the store, which passes the current state and action to the relevant reducer — a pure function that returns the next state without mutating the original. The store replaces its state with the returned value and notifies all subscribed selectors, triggering component re-renders where the selected slice changed.
Use local component state (`useState`, `ref`) for UI state that is isolated to a single component: form inputs, toggle visibility, hover state. Use a global store for state that multiple unrelated components need to read or write: authenticated user data, shopping cart contents, application-wide notifications. Lifting state to a global store prematurely adds boilerplate without benefit.
Redux is framework-agnostic, uses explicit action objects and pure reducers, and has a strong devtools and middleware ecosystem (Redux Thunk, Redux Saga). Pinia is Vue-specific, uses a simpler store definition with `state`, `getters`, and `actions` (no separate action types or reducers), and integrates natively with Vue's reactivity system. For Vue projects Pinia is the officially recommended choice; for React projects Redux Toolkit or Zustand are the common options.
mermaid
flowchart LR A[User Interaction] --> B[Dispatch Action] B --> C{Async operation?} C -- Yes --> D[Middleware handles async] D --> E[API or IO call] E --> F[Dispatch Result Action] F --> G[Reducer or Mutation] C -- No --> G G --> H[Compute Next State] H --> I[Store Updated] I --> J[Notify Subscribed Components] J --> K{State slice changed?} K -- No --> L[Skip Re-render] K -- Yes --> M[Component Re-renders] M --> N[User Sees Updated UI] style N fill:#22c55e,color:#fff
Copied to clipboard