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

What is a Render Prop?

A render prop is a function prop that a component calls to determine what to render, enabling flexible composition patterns.

What is a Render Prop?

You'll learn what a render prop is and how it enables flexible, reusable component composition.

The Core Idea

A render prop is a function that you pass as a prop to a component, and that component calls your function to determine what it should render. Instead of the component deciding its own output, it delegates that decision to you—the parent—by invoking the function you provided.

Think of it like hiring a chef who specializes in preparing ingredients perfectly, but lets you decide how to plate and serve the dish. The component does the complex work (managing state, handling side effects, encapsulating logic), then hands you the results and says, "Here's what I've got—you decide what to display."

Why It Matters

Render props solve the problem of sharing stateful logic between components without dictating what that logic looks like on screen. The component with the render prop handles the "how it works" part, while you retain complete control over the "what it looks like" part.

The function you pass typically receives data or methods as arguments, which you can use to render whatever JSX you want. This pattern inverts control: instead of the component rendering a fixed UI, it renders whatever your function returns.

The Pattern in Plain English

  1. A component accepts a prop that is a function
  2. That component calls the function at render time
  3. The function returns JSX to render
  4. The component renders whatever the function returned

Key Takeaway: A render prop is a function prop that a component calls to determine what to render, giving you full control over the UI while the component manages the logic behind it.