What is prop drilling?
Prop drilling is passing props through several layers of components that do not use them, only so a deeply nested component can receive them. It makes code verbose, couples intermediate components to data they do not care about, and makes refactoring harder.
Why it happens
State is lifted to a high-level component (often the app root), but the consumer is many levels down: App > Layout > Sidebar > Menu > UserBadge.
Is it always bad?
No. Passing props two or three levels is explicit and easy to follow. It becomes a problem when many intermediate components forward the same props.
Solutions
- Composition: pass components as
childrenor slot props so the parent renders the consumer directly. Often the simplest fix. - Context:
createContextplususeContext(or React 19'suse(Context)) for values many components need: theme, current user, locale. Render<UserContext value={user}>directly in React 19. - State libraries: Zustand, Jotai or Redux Toolkit for frequently changing global state with selective subscriptions.
- Server state libraries: TanStack Query or SWR let any component read cached server data by key.
- Frameworks: Server Components can fetch data right where it is used.
Context caveat
Every consumer re-renders when the context value changes. Split contexts or use a store when values change often.
Code example
1import { createContext, use, useState } from "react";23type User = { name: string };45// Drilling: Layout and Sidebar only forward `user`6// <Layout user={user}><Sidebar user={user}><UserBadge user={user} /></Sidebar></Layout>78// Fix with context (React 19 syntax)9const UserContext = createContext<User | null>(null);1011function UserBadge() {12 const user = use(UserContext); // read directly, no drilling13 return <span>{user?.name ?? "Guest"}</span>;14}1516function Sidebar() {17 return <aside><UserBadge /></aside>; // no user prop needed18}1920export function App() {21 const [user] = useState<User>({ name: "Ada" });22 return (23 <UserContext value={user}>24 <Sidebar />25 </UserContext>26 );27}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.