Labs ICT
โญ Pro Login

Prop Drilling

The problem and why we need better solutions.

What is Prop Drilling?

Imagine you're playing telephone in a classroom. The teacher tells the first student a message, who whispers it to the next, and so on down the line. By the time it reaches the last student, the message might be completely garbled.

Prop drilling works the same way. You pass a prop from a parent component down through multiple layers of children, even though only the deeply nested component actually needs it.

It's not the end of the world for one or two levels, but when you're drilling through five or six components just to get a value where it needs to be, things get messy fast.

The Problem

Here's what prop drilling looks like in practice. You start with a state value in your App component and need it in a deeply nested child.

function App() {
  const [user, setUser] = useState({ name: "Bilal" });
  return <Layout user={user} />;
}

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

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

function UserProfile({ user }) {
  return <h1>Welcome, {user.name}</h1>;
}

See that? Layout doesn't care about user. Sidebar doesn't care about user. But they both have to receive and pass it along anyway. They're basically just middlemen carrying a package they never open.

Try it Yourself โ†’

When It Gets Painful

Prop drilling becomes a real headache when you have multiple values drilling through many layers. Imagine passing theme, user, notifications, and language settings through the same chain of components.

Every intermediate component gets cluttered with props it doesn't use. Your component signatures start looking like a grocery list. And changing one value means updating every single component in the chain.

The worst part? When you finally refactor and realize three of those middle components were just glorified pass-throughs with zero logic of their own.

What Are Your Options?

Don't panic. You've got several solid alternatives to prop drilling. The most common is React's Context API, which lets you share values across the component tree without passing props through every level.

const UserContext = createContext(null);

function App() {
  const [user, setUser] = useState({ name: "Bilal" });
  return (
    <UserContext.Provider value={user}>
      <Layout />
    </UserContext.Provider>
  );
}

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

State management libraries like Redux or Zustand also solve this problem for more complex scenarios. The key takeaway is: if you're drilling through more than two levels, it's time to reach for a better tool.

Try it Yourself โ†’

๐Ÿงช Quick Quiz

What is prop drilling?