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

Function Children vs Named Render Props

Comparing children-as-function to explicit render prop names and when each syntax is clearer.

Function Children vs Named Render Props

What you'll learn: How to choose between passing a function as children versus using an explicit prop name like render.


At this point, you've seen render props work two ways:

// Named render prop
<MouseTracker render={(x, y) => <div>Mouse at {x}, {y}</div>} />

// Children as function
<MouseTracker>
  {(x, y) => <div>Mouse at {x}, {y}</div>}
</MouseTracker>

Both patterns accomplish the same goal—letting the parent control what gets rendered—but they feel different to use.

When to Use Named Props

Use a named prop like render when:

  • Your component accepts multiple render functions (e.g., renderHeader and renderFooter)
  • The function isn't the "main" content, but a customization option
  • You want to be explicit about what the function does
<DataTable 
  render={(row) => <TableRow data={row} />}
  renderEmpty={() => <p>No data</p>}
/>

When to Use Children-as-Function

Use children as a function when:

  • There's only one render function needed
  • The function feels like the "primary content" of the component
  • You want cleaner, more readable JSX (less prop noise)
<MouseTracker>
  {(x, y) => <Cursor x={x} y={y} />}
</MouseTracker>

Think of it like HTML: you write <button>Click me</button>, not <button text="Click me" />—because the content is the main point. Same logic applies here.

Key Takeaway: Use children for single, primary render functions; use named props when you have multiple functions or need explicit labeling for clarity.