Client-Side State Management
Why component-local state stops scaling, and the patterns — lifting state up, shared providers, external stores — that fix it in any framework.
Client-Side State Management
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Component-local state works until two components that don't share a parent need the same data, which is when a dedicated sharing strategy becomes necessary.
- Lifting state up means moving state to the nearest common ancestor of the components that need it, and passing it down as props — simple, but it causes prop drilling as the tree gets deeper.
- A context-style provider lets any descendant read or update shared state directly, without every component in between having to forward props it doesn't use.
- External stores like Redux, Zustand, and Pinia move state outside the component tree entirely, trading some setup overhead for predictable updates and easier debugging in large apps.
- The right choice depends on scale: local state for one component, lifting for a small cluster, a provider for broader sharing, and an external store once updates get complex or frequent across the app.
The problem: two components, one piece of data
A single component managing its own state is the easy case. A search box tracks its own input value, a dropdown tracks whether it’s open — nobody else cares. The problem shows up the moment two components that don’t share a parent both need the same piece of data. Say a shopping cart icon in the header needs to show a count, and a product list buried three levels deep needs to add items to that same cart. Neither owns the data naturally. This isn’t a React problem, or a Vue problem, or a Svelte problem — it’s a problem with any UI built out of components, because components are supposed to be self-contained, and self-contained things don’t automatically know about each other.
Lifting state up: the obvious first move
The first fix, and the right one for small cases, is to move the state up to the nearest common ancestor of the components that need it. If the cart icon and the product list both live inside some App component, the cart data lives in App, and gets handed down as props to whichever children need to read or change it. This is called “lifting state up,” and it’s not a trick — it’s just recognizing that shared data needs a shared owner.
The catch is what happens as the tree grows. If the component that needs the cart data is five layers below App, every component in between has to accept a cart prop and a setCart function, just to pass them along to its children. None of those middle components care about the cart. They’re just plumbing. This is called prop drilling, and it’s the textbook sign that lifting state up has been stretched past where it comfortably works.
Providers: a shared drawer instead of a relay race
The fix for prop drilling is to stop relaying the data through every layer and instead make it directly reachable from anywhere below where it’s defined. Think of it like a supply closet on a single floor of an office, versus making every person on every floor personally carry the stapler down the hall to whoever needs it. A provider (React calls this Context, Vue has provide/inject, Svelte has context too) declares a piece of state once, near the top of the tree, and any descendant can reach in and grab it directly — no middleman components required.
This solves prop drilling cleanly for data that doesn’t change too often — theme settings, the logged-in user, locale preferences. It gets less comfortable when the data changes constantly, because in several frameworks, updating a context value can cause every component reading it to re-render, even ones that only care about a small slice of that data.
External stores: taking state out of the tree completely
Once an app has many pieces of state updating frequently, interacting with each other, and needing to be read from far-flung parts of the UI, libraries like Redux, Zustand, or Vue’s Pinia take a different approach: state lives in a store that exists outside the component tree entirely, as its own independent object. Components subscribe to exactly the slices of that store they care about, and only re-render when those specific slices change. Updates typically happen through defined actions or setter functions rather than scattered setState calls, which makes it much easier to trace why a given piece of state changed when debugging a large app.
The conceptual shift that matters here, across every one of these libraries, is that state management stops being “a value some component happens to hold” and becomes its own subsystem, with its own rules for reading and writing. That’s a meaningfully different mental model from local state, which is why it’s worth learning as a strategy, not as a specific API from a specific framework.
Choosing a level, not a library
None of these four approaches is categorically better — they sit on a scale. Local state for data one component owns alone. Lifting state up for a small, shallow cluster of components. A provider once sharing needs to reach further down the tree without plumbing through every layer. An external store once the app has enough independently-updating state that tracking it by hand becomes the actual bottleneck. Most real apps use all four at once, in different corners of the UI — the skill isn’t picking one pattern forever, it’s recognizing which level a given piece of state actually lives at.
Check yourself
What problem does lifting state up solve, and what new problem does it tend to create as an app grows?
It solves the problem of two sibling components needing the same data by moving that data to their nearest common ancestor and passing it down as props. As the component tree gets deeper, this creates prop drilling, where components in the middle of the tree have to accept and forward props they never actually use themselves.
How does a context-style provider differ from simply lifting state further up the tree?
Lifting state up still requires passing it down as props through every intermediate component, whether or not that component needs it. A provider instead makes the shared state directly readable by any descendant that asks for it, skipping the intermediate components entirely, regardless of how deep the tree is.
Why would a team reach for an external store like Redux or Zustand instead of just using a built-in context provider?
Context is built for passing data down a tree, but it does not give you fine-grained control over when components re-render, and it can get unwieldy once many different pieces of state update independently and frequently. External stores add structure for update logic, selective subscriptions, and debugging tools, which pays off once the app's state is large or changes often.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.