100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
React

Prop Drilling in React

Explore the problem of passing props through many intermediate components and the patterns used to avoid it.

Props & StateIntermediate9 min readJul 8, 2026
Analogies

Introduction

Prop drilling occurs when data must be passed through several layers of components — via props — purely so that a deeply nested descendant can access it, even though the intermediate components have no use for that data themselves. As applications grow, prop drilling makes components harder to maintain, since every intermediate layer must accept and forward props it does not otherwise care about.

🏏

Cricket analogy: A message from the coach to the No.11 batsman gets relayed through the captain, then the vice-captain, then the fielding coach, none of whom need the message themselves, just to reach the last man.

Syntax

jsx
function App() {
  const user = { name: 'Riya' };
  return <Layout user={user} />;
}

function Layout({ user }) {
  return <Sidebar user={user} />;
}

function Sidebar({ user }) {
  return <UserCard user={user} />;
}

function UserCard({ user }) {
  return <p>Welcome, {user.name}</p>;
}

Explanation

In this example, Layout and Sidebar don't use the user prop at all — they simply forward it down to UserCard, which is the only component that actually needs it. This chain works but becomes a maintenance burden: renaming a prop, adding a new one, or reorganizing the component tree means touching every intermediate component along the path.

🏏

Cricket analogy: Layout is like the team manager and Sidebar the twelfth man — both just hand the scorecard to the wicketkeeper (UserCard) who actually reads it, but if the scorecard format changes, the manager and twelfth man's handoff routine must change too.

Example

jsx
// Avoiding prop drilling with the Context API
import { createContext, useContext } from 'react';

const UserContext = createContext(null);

function App() {
  const user = { name: 'Riya' };
  return (
    <UserContext.Provider value={user}>
      <Layout />
    </UserContext.Provider>
  );
}

function Layout() {
  return <Sidebar />;
}

function Sidebar() {
  return <UserCard />;
}

function UserCard() {
  const user = useContext(UserContext);
  return <p>Welcome, {user.name}</p>;
}

Output

The rendered output is identical ("Welcome, Riya"), but Layout and Sidebar no longer need to know about the user prop at all. UserCard reads the value directly from context via useContext, decoupling the intermediate components from data they never used. Component composition (passing components as children/props) is another common way to sidestep drilling for simpler cases.

🏏

Cricket analogy: Instead of relaying through the manager and twelfth man, the wicketkeeper now checks the scoreboard (context) directly for the batsman's name, so the manager and twelfth man no longer need to know it exists.

Key Takeaways

  • Prop drilling means forwarding props through components that don't use them, just to reach a deeply nested child.
  • It increases coupling and makes refactoring intermediate components error-prone.
  • The Context API is a common solution for global or widely-needed data (theme, auth, locale).
  • Component composition (children props) can eliminate drilling in simpler nesting scenarios.
  • State management libraries (e.g. Redux) offer another solution for complex, app-wide state sharing.

Practice what you learned

Was this page helpful?

Topics covered

#React#ReactJsStudyNotes#WebDevelopment#PropDrillingInReact#Prop#Drilling#Syntax#Explanation#StudyNotes#SkillVeris