When NOT to Use Context: Single Consumer
What you'll learn: You'll learn to recognize when passing props directly is simpler than setting up context, specifically when state only flows to one component.
The Single Consumer Smell
Context shines when multiple components at different nesting levels need the same data. But what if only one component actually uses that value?
Imagine installing a city-wide PA system just to tell your neighbor dinner is ready. Context is infrastructure—it has overhead. If you're only feeding data to a single consumer, you're building unnecessary plumbing.
Why It's Unnecessary Overhead
When you create a context for a single consumer, you're adding:
- A context object (
createContext) - A provider component wrapping part of your tree
- A consumer component using
useContext - Extra indirection that makes data flow harder to trace
All to avoid passing one prop.
The Simple Alternative
If ComponentA needs to pass data to ComponentB, and ComponentB is the only component that needs it, just pass props:
// ❌ Overkill: Context for one consumer
<ThemeProvider value="dark">
<Header /> {/* doesn't use theme */}
<Sidebar /> {/* doesn't use theme */}
<Button /> {/* only Button needs it */}
</ThemeProvider>
// ✅ Better: Direct prop
<Layout>
<Header />
<Sidebar />
<Button theme="dark" />
</Layout>
Even if Button is nested a few levels down, prop drilling through 2-3 components is fine. It's explicit, traceable, and simpler.
When to Reconsider
If more components start needing the same data, then upgrade to context. Start simple; refactor when complexity justifies it.
Key Takeaway: Context is for sharing state across multiple consumers—if only one component needs the data, pass it as a prop directly.