You manage state in a frontend application by keeping each piece of data in the smallest place that needs it, lifting it to a common parent when several components share it, and using a dedicated store only for data that many distant parts of the app read. Separate server data (fetched from an API) from client data (UI choices), because they need different tools. This guide explains frontend state management with React examples, and the same principles apply in Vue and Angular.
State is any data that changes over time and affects what the user sees: a form input, an open menu, a logged-in user, a list loaded from a server.
Most bugs in state management come from treating all state the same. Sort it first.
| Kind | Example | Typical tool |
|---|---|---|
| Local UI state | Is a dropdown open, text in an input | Component state (useState) |
| Shared client state | Theme, shopping cart, sidebar | Lifted state, context or a store |
| Server state | Product list, user profile from an API | A data-fetching library with caching |
| URL state | Current page, filters, search query | The router and query string |
| Form state | Values, errors, touched fields | A form library or local state |
Keep state inside the component that uses it. This is the simplest option and needs no extra library.
Nothing else in the app cares whether this accordion is open, so nothing else should know.
When two sibling components need the same data, move it to their closest common parent and pass it down as props, with callbacks for changes.
Derive values instead of storing them. Here shown is computed during render, so there is no second copy of the data that can fall out of sync.
Passing props through many layers (prop drilling) becomes tedious. Context makes a value available to a whole subtree.
Context suits values that change rarely, such as theme, locale or the current user. Every consumer re-renders when the value changes, so avoid putting fast-changing data in a single big context.
When many unrelated components read and write the same data, a store helps. Popular choices are Redux Toolkit, Zustand and Jotai in React, Pinia in Vue, and signals or services in Angular. A small Zustand example:
Updates are immutable: you return new objects and arrays rather than changing existing ones, which lets the framework detect changes cheaply and keeps history predictable.
Data from an API has special problems: loading and error states, caching, refetching, duplicate requests and staleness. Tools such as TanStack Query or SWR handle these for you.
Copying fetched data into a global store by hand usually duplicates what these libraries already do and leads to stale data.
No. Many applications work well with local state, context and a server-state library. Add a store when shared client state becomes hard to follow.
It is passing a prop through several components that do not use it, only to reach a deep child. Context, composition or a store can remove it.
Usually inside the form component, or in a form library when you need validation and many fields. Move it up only when other components need the values.
The ideas match. Vue uses ref, reactive and Pinia, and Angular uses signals and injectable services, but local first, lift up, then store applies everywhere.
Manage frontend state by classifying it: local UI state, shared client state, server state, URL state and form state. Start local, lift up when needed, use context for rarely changing global values, add a store for complex shared data, and let a data-fetching library handle server data. Derive instead of duplicating, and never mutate state in place.