AceDevHub
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.

TechniqueBest fitTrade-off
PropsExplicit parent-to-child data flowCan become repetitive across deep trees
Composition / childrenLet a parent supply UI without threading every data propDoes not solve every shared-data case
ContextAmbient data needed by many distant descendantsCreates 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.