When developers first learn about the prop-drilling problem, their immediate impulse is often to reach for the Context API for everything. However, wrapping components in multiple Context Providers introduces architectural overhead, complicates component testing, and risks unnecessary render cascades.
Before reaching for Context, the React core team recommends an alternative, simpler architectural solution: Component Composition.
By taking advantage of children and passing fully-formed JSX elements down through props, you can often eliminate prop drilling entirely without creating a single Context!
childrenIn the composition pattern, the top-level parent creates the <UserBadge> component directly and passes it as a child.
The intermediate components (<Page>, <Dashboard>, <Sidebar>) do not need to know what a "user" is; they simply render children inside their layout shells:
| Feature | Component Composition | React Context API |
|---|---|---|
| Complexity | Lowest (Standard props & children) | Medium (Providers, Hooks, modules) |
| Component Coupling | Zero coupling; containers remain pure | Consumers are coupled to Context object |
| Best For | 2–4 levels of nesting, layout shells | Truly global ambient data (Auth, Theme) |
| Testing | Trivial (no mocking providers required) | Requires wrapping tests in <Provider> |
<Dashboard><Sidebar><UserMenu user={user} /></Sidebar></Dashboard>, where does user get passed into <UserMenu>?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Event Bubbling Through Portals Explained | Slot Pattern and Passing JSX Elements as Props |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.