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.

Web Stop 1 of 1 By UniqBlog Desk 30 November 2026 Updated 1 December 2026 6 min read

Soft 3D illustration: a red-orange parcel dropping level by level through holes in a tower of four stacked boxes, beside a clear tube where a capsule shoots straight down

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 children instead. Most "drilling" goes away.
  • Context suits low-frequency, app-wide values. Every consumer re-renders when the provider's value changes, and memo does 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 rendersUserName renders
One context { cart, user } + useMemo22
Two contexts, CartContext and UserContext21
Zustand store with selectors21

The counts include the first mount, so "1" means the component did not re-render. The ways to fix it are:

  1. Memoize the value. If the provider builds { user, login } inline, every parent render creates a new object. Use useMemo and useCallback, as the useContext docs show.
  2. 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.
  3. 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:

ContextZustand 5Redux Toolkit 2Jotai 3
ModelValue passed down the treeOne store hook, selectorsOne store, slices, actionsMany small atoms
Provider neededYesNoYes (react-redux)Optional
Re-rendersAll consumers on value changeOnly on selected slice changeOnly on selected slice changeOnly atoms you read
Good forTheme, locale, auth userApp state with little setupLarge apps, strict patterns, RTK QueryFine-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 children or 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

UniqBlog Desk · Editors

The editors of UniqBlog. Tested tutorials and tech news for working developers.

Further along the line