What is a Render Prop?
You'll learn what a render prop is and how it lets components share logic while keeping rendering flexible.
A render prop is a pattern where you pass a function as a prop to a component. That function returns JSX, which the component then renders. This lets the component provide logic or data, while the consumer decides what the UI should look like.
Think of it like a restaurant kitchen that prepares ingredients for you, but you decide how to plate the dish.
The Basic Idea
Instead of a component deciding what to render internally, it calls a function you provide and renders whatever that function returns:
function DataProvider({ render }) {
const data = "Some data from provider";
return render(data); // Call the function, render its result
}
// Usage
<DataProvider
render={(data) => <p>{data}</p>}
/>
Here, DataProvider doesn't hardcode <p> tags. It calls the render prop (a function), passes data to it, and renders whatever comes back.
Why This Matters
Render props solve a key problem: how to share logic without forcing a specific UI. The component handles the "what to do," while you control the "how to show it."
You've seen prop drilling and callbacks already. Render props extend that idea: instead of passing data down or events up, you pass rendering instructions down as a function.
Common Variations
The prop doesn't have to be named render. You'll often see children used as a function instead (covered later), but the principle is identical.
Key Takeaway: A render prop is a function passed as a prop that returns JSX, letting components share logic while consumers control the rendering.