Intermediate React Interview QuestionsIntermediateComparison
React · Question 59
When should you use Context instead of props or component composition?
Direct answer
Use props for explicit local data flow, composition when intermediate components only need to pass UI through, and Context when distant descendants genuinely need the same ambient value.
| Technique | Best fit | Trade-off |
|---|---|---|
| Props | Explicit parent-to-child data flow | Can become repetitive across deep trees |
| Composition / children | Let a parent supply UI without threading every data prop | Does not solve every shared-data case |
| Context | Ambient data needed by many distant descendants | Creates an implicit dependency and can broaden updates |
Common Context examples include theme, current account, routing-like ambient data, and shared state for a subtree. But prop drilling alone is not proof that every value belongs in Context.