Course contentsShow
← React
Lesson 826 of 2,39621. Context FundamentalsFree lesson

Comparing Solutions: Props vs Composition vs Context

Decision framework for choosing between explicit props, composition patterns, or Context based on tree depth.

Comparing Solutions: Props vs Composition vs Context

You'll learn: A practical decision framework for choosing between explicit props, component composition, or Context based on your component tree's depth and complexity.

The Three-Way Choice

When data needs to flow through your component tree, you have three main approaches. Each has a sweet spot:

Explicit Props shine when data travels 1-2 levels deep. They're visible, predictable, and easy to trace. If <Parent> passes to <Child> directly, props are perfect.

Component Composition works when intermediate components don't need the data. Instead of drilling props through layers that ignore them, pass configured child components through the middle layers. Think of it like packing a sealed box through a shipping chain—the middle handlers don't open it, they just pass it along.

Context solves deep tree problems (3+ levels) where multiple branches need the same data. It's your escape hatch when props create maintenance nightmares and composition feels forced.

Decision Framework

Ask yourself:

  1. How many levels? (1-2 → props, 3+ → consider alternatives)
  2. Do middle components use this data? (Yes → props, No → composition)
  3. How many branches need it? (One path → composition, Multiple → Context)
  4. How often does it change? (Rarely → Context okay, Constantly → reconsider)

Think of it like delivering a package: hand delivery for neighbors (props), leaving it at the front desk for roommates (composition), or broadcasting on the building intercom (Context).

When in Doubt

Start with props. They're explicit and traceable. Refactor to composition if drilling gets annoying. Reach for Context only when both feel inadequate—usually at 3+ levels with multiple consuming branches.

Key Takeaway: Choose props for shallow trees, composition to skip ignorant middle layers, and Context for deep trees with multiple consumers—each tool has its depth and complexity threshold.