A Simple Drilling Example
What you'll learn: How to trace data through multiple component layers when intermediate components don't actually use that data themselves.
The Scenario
Imagine you have a theme setting (like "dark" or "light") at the top of your app, but only a deeply nested component needs to display it. Every component in between must still receive and pass it down.
function App() {
const theme = "dark";
return <Parent theme={theme} />;
}
function Parent({ theme }) {
// Parent doesn't use theme at all
return <Middle theme={theme} />;
}
function Middle({ theme }) {
// Middle doesn't use theme either
return <GrandChild theme={theme} />;
}
function GrandChild({ theme }) {
// Finally! Someone who needs it
return <div className={theme}>Themed content</div>;
}
Why This Matters
Notice how Parent and Middle act like messengers—they receive theme in their props and immediately hand it down, without using it themselves. This is prop drilling in action.
Think of it like passing a package through a chain of people: even if the folks in the middle don't care what's inside, they still have to hold it and pass it along to reach the final recipient.
The Cost
Both Parent and Middle now have theme cluttering their prop lists, even though they don't need it. If theme changes, all three components re-render (though that's normal React behavior).
Key Takeaway: Prop drilling happens when data flows through components that don't use it—they're just passing it down the tree to where it's actually needed.