Prop drilling in React: when to use Context or a store
Prop drilling in React is fine more often than you think. Here is when to switch to composition, Context or a state library, with tested React 19 code.
Prop drilling in React means passing a prop through components that do not use it, only so a deeper child can. It is fine for two or three levels. Past that, try composition (children and JSX props) first, then Context for values that change rarely, such as theme, locale or the current user. Use a state library like Zustand when many components read and write shared state that changes often.
Everything below was written against React 19.3.1, Zustand 5.1.0 and Jotai 3.0.2 (the npm latest tags on 2026-12-01). Every snippet was rendered in Node with react-dom, and the re-render counts quoted come from that run.
Key takeaways
- Drilling props two or three levels is explicit and easy to follow. The React docs tell you to start there.
- When the middle components only forward data, pass JSX as
childreninstead. Most "drilling" goes away. - Context suits low-frequency, app-wide values. Every consumer re-renders when the provider's
valuechanges, andmemodoes not stop it. - For busy shared state such as carts, editors and filters, a store with selectors re-renders only the components whose slice changed.
What is prop drilling, and when is it fine?
Here Page and Header receive user only to pass it on:
function Page({ user }) {
return <Header user={user} />;
}
function Header({ user }) {
return <nav><Avatar user={user} /></nav>;
}
function Avatar({ user }) {
return <img alt={user.name} src={user.avatarUrl} />;
}
This is not a bug. The React docs' Before you use context section says to start by passing props, because it "makes it very clear which components use which data". You can search for user= and see the whole path.
Drilling becomes a problem when:
- the same prop passes through four or more layers that never read it;
- adding one field means editing five component signatures;
- several unrelated subtrees need the same value; or
- intermediate components re-render only because they forward a changing prop.
How does composition with children fix most drilling?
The same React page gives the second step: "Extract components and pass JSX as children". If Layout takes slots instead of data, the data skips the middle layers entirely:
function Layout({ header, children }) {
return (
<div className="layout">
<header>{header}</header>
<main>{children}</main>
</div>
);
}
function App({ user }) {
return (
<Layout header={<Avatar user={user} />}>
<Feed />
</Layout>
);
}
Layout no longer knows that user exists. The component that owns the data builds the element, and the layout just places it. Try this before you add any shared-state tool.
When should you use React Context?
Use Context when many components at different depths need the same value, and that value changes rarely. Typical examples are theme, locale, the signed-in user, feature flags and a design-system config.
In React 19 you render the context itself as the provider. createContext says: "Starting in React 19, you can render <SomeContext> as a provider. In older versions of React, use <SomeContext.Provider>."
import { createContext, useContext, use } from 'react';
const ThemeContext = createContext('light');
function App() {
return (
<ThemeContext value="dark">
<ThemeButton />
<Hint show />
</ThemeContext>
);
}
function ThemeButton() {
const theme = useContext(ThemeContext);
return <button className={theme}>Save</button>;
}
function Hint({ show }) {
if (!show) return null;
const theme = use(ThemeContext); // `use` may be called after an early return
return <p className={theme}>Tip</p>;
}
use reads a context like useContext does. Unlike a hook, it can be called inside conditions and after early returns.
Why does Context cause extra re-renders?
The useContext caveats are precise. React re-renders every consumer below a provider that receives a different value, compared with Object.is. Also, "Skipping re-renders with memo does not prevent the children receiving fresh context values."
So one big context object is the classic trap. In the test below, a single AppStateContext holds { cart, user } (wrapped in useMemo). Adding one cart item re-rendered both CartBadge and a memo-wrapped UserName, although user had not changed:
| Setup (one cart update) | CartBadge renders | UserName renders |
|---|---|---|
One context { cart, user } + useMemo | 2 | 2 |
Two contexts, CartContext and UserContext | 2 | 1 |
| Zustand store with selectors | 2 | 1 |
The counts include the first mount, so "1" means the component did not re-render. The ways to fix it are:
- Memoize the value. If the provider builds
{ user, login }inline, every parent render creates a new object. UseuseMemoanduseCallback, as the useContext docs show. - Split contexts by how often they change. Keep the user in one context and the cart in another. Put a state value and its setter in separate contexts if needed.
- Move fast-changing state to a store once splitting stops being enough.
When should you reach for a state library?
Pick a library when shared state is written from many places, changes often, or needs derived values and devtools. Here is how the three common choices compare:
| Context | Zustand 5 | Redux Toolkit 2 | Jotai 3 | |
|---|---|---|---|---|
| Model | Value passed down the tree | One store hook, selectors | One store, slices, actions | Many small atoms |
| Provider needed | Yes | No | Yes (react-redux) | Optional |
| Re-renders | All consumers on value change | Only on selected slice change | Only on selected slice change | Only atoms you read |
| Good for | Theme, locale, auth user | App state with little setup | Large apps, strict patterns, RTK Query | Fine-grained, derived state |
Zustand is the smallest step up. Its README says to "Use the hook anywhere, no providers are needed":
import { create } from 'zustand';
const useCart = create((set) => ({
items: [],
addItem: (item) => set((state) => ({ items: [...state.items, item] })),
}));
function CartBadge() {
const count = useCart((s) => s.items.length); // re-renders only when the count changes
return <span>{count}</span>;
}
function AddButton() {
const addItem = useCart((s) => s.addItem);
return <button onClick={() => addItem('book')}>Add</button>;
}
Select primitives or stable references. A selector that returns a new object on each call makes the component re-render every time. For that case, Zustand ships useShallow.
Jotai splits state into atoms, and derived atoms recompute from them:
import { atom, useAtomValue, useSetAtom } from 'jotai';
const cartAtom = atom([]);
const cartCountAtom = atom((get) => get(cartAtom).length);
function CartBadge() {
return <span>{useAtomValue(cartCountAtom)}</span>;
}
function AddButton() {
const setCart = useSetAtom(cartAtom);
return <button onClick={() => setCart((c) => [...c, 'book'])}>Add</button>;
}
Redux Toolkit is the heavier, structured option. If you use Redux at all, the Redux docs are blunt: "you should be using Redux Toolkit" rather than the legacy redux core (why RTK is Redux today). Choose it when a large team wants one enforced pattern, time-travel devtools, or RTK Query for server data.
Server data such as API responses, caching and refetching usually belongs in a data-fetching library or your framework's loaders, not in any of these stores.
Which should you use? A checklist
Go down the list and stop at the first match:
- [ ] Data passes through two or three layers? Keep the props.
- [ ] Middle components only forward it? Use
childrenor JSX props. - [ ] Many components need it, and it changes rarely? Use Context, one per concern, with a memoized value.
- [ ] Many components read and write it, and it changes often? Use Zustand or Jotai.
- [ ] Large team, strict conventions, heavy devtools needs? Use Redux Toolkit.
Before you switch, profile with React DevTools. If nothing re-renders badly, drilling a few props is a style question, not a performance problem.
Sources
- Passing Data Deeply with Context, react.dev
- createContext, useContext, use, react.dev
- React versions, react.dev
- Zustand docs and Jotai docs
- Why Redux Toolkit is how to use Redux today, redux.js.org
UniqBlog Desk · Editors
The editors of UniqBlog. Tested tutorials and tech news for working developers.
Further along the line

Kubernetes vs Docker: which one do you actually need?
Kubernetes vs Docker is not either-or: Docker builds and runs containers, Kubernetes schedules them across machines. Here is when each layer earns its cost.

Docker Compose volumes: bind mounts, tmpfs and backups
Docker Compose volumes explained with a tested compose file: when to use named volumes, bind mounts or tmpfs, how to name them, and how to back up and restore one.

PostgreSQL vs MySQL in 2026: which database should you pick?
PostgreSQL vs MySQL compared on current versions: JSON, CTEs, window functions, extensions, replication, licensing and cost, with SQL we ran on both.

Secrets management across environments: a practical ladder
A secrets management ladder for dev, staging and prod: from .env files to SOPS and age, cloud secret managers, Vault or OpenBao, and External Secrets Operator.