Course contentsShow
← React
Lesson 1136 of 2,39629. Composition: SlotsFree lesson

Slots vs Render Props: The Tradeoff

Comparing static slot props with dynamic render props, and when each pattern provides better ergonomics.

Slots vs Render Props: The Tradeoff

You'll learn when to choose static slot props versus dynamic render props for content customization.

The Core Difference

Slots and render props solve similar problems—customizing parts of a component—but with different philosophies:

Slots are static: you pass in pre-built JSX elements as props. The parent component decides what to render and passes it down complete.

Render props are dynamic: you pass in a function that the component calls with data. The component controls when and what data to provide, while you control how to render it.

When Slots Win

Use slots when the content doesn't need access to the component's internal state:

// Clean and simple - no internal data needed
<Card 
  header={<h2>Title</h2>}
  footer={<button>Close</button>}
/>

Slots provide better ergonomics for simple cases: just pass JSX directly, no function wrapper needed.

When Render Props Win

Use render props when you need the component's internal data to make rendering decisions:

// Component shares its data with you
<MouseTracker 
  render={({ x, y }) => (
    <div>Mouse is at {x}, {y}</div>
  )}
/>

The render prop pattern is essential when the rendering depends on state the component owns.

The Ergonomics Tradeoff

Slots feel lighter and more intuitive—they're "just props." Render props add a function layer but unlock dynamic behavior. Choose based on whether you need access to internal state or just want to fill a placeholder.

Key Takeaway: Use slots for static content customization (better ergonomics), and render props when you need dynamic access to the component's internal state or behavior.