Course contentsShow
← React
Lesson 1052 of 2,39627. Composition: Render PropsFree lesson

When Render Props Add Value

Use render props when you need to share logic but the presentation varies widely, and hooks don't fit the problem.

When Render Props Add Value

You'll learn when render props are the right choice for sharing logic while allowing flexible presentation.

Render props shine in specific situations: when you need to share behavior but the visual output varies dramatically between uses, and React hooks can't elegantly solve the problem.

The Sweet Spot

Render props add value when:

  1. Presentation is unpredictable — You're building reusable logic but have no idea how consumers will display the data. A mouse tracker might render coordinates as text, visualize them as a dot, control an animation, or trigger sound effects.

  2. Multiple distinct outputs from one source — The same component might need to render different UI in different parts of the same tree using the same underlying logic.

  3. Hooks don't fit naturally — Some patterns (like providing rendering slots or plugin systems) don't map well to hooks' linear call structure.

When NOT to Use Them

If you're sharing logic and the presentation is either fixed or simple, custom hooks are usually better. They're cleaner, easier to test, and compose more naturally.

For example, managing form input state? Use useForm. Fetching data? Use useFetch. These solve logic-sharing without needing render functions.

The Decision Framework

Ask yourself:

  • Do I need to share logic? (If no, just use a regular component)
  • Does the consumer need full control over rendering? (If yes, render prop)
  • Is it pure logic with minimal/fixed UI? (If yes, custom hook)

Render props are powerful but come with complexity. Use them when the flexibility they provide genuinely solves a problem that simpler patterns can't.

Key Takeaway: Use render props when you need to share logic but presentation varies widely across use cases, and the pattern doesn't reduce cleanly to a custom hook.