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

Multiple Render Props on One Component

A component can accept multiple render functions for different slots, enabling fine-grained control over various parts.

Multiple Render Props on One Component

You'll learn how to accept multiple render functions in a single component, giving consumers precise control over different parts of the UI.


The Core Idea

A component doesn't have to limit itself to one render prop. You can accept multiple render functions as props, each responsible for rendering a different "slot" or section of your component. This gives consumers fine-grained control: they can customize the header, footer, content, or any other part independently.

Think of it like a customizable form template where you can plug in different sections: one function draws the header, another draws the submit button, and another renders the input fields—all in the same component.


How It Works

Instead of passing a single render or children function, you accept multiple named props like renderHeader, renderFooter, and renderBody. Your component calls each at the appropriate place in its JSX, passing relevant data to each.

function DataPanel({ data, renderHeader, renderBody, renderFooter }) {
  return (
    <div className="panel">
      <div className="header">{renderHeader(data)}</div>
      <div className="body">{renderBody(data)}</div>
      <div className="footer">{renderFooter(data)}</div>
    </div>
  );
}

// Usage
<DataPanel
  data={user}
  renderHeader={(u) => <h2>{u.name}</h2>}
  renderBody={(u) => <p>{u.bio}</p>}
  renderFooter={(u) => <button>Contact {u.name}</button>}
/>

Each render function receives the data it needs and returns JSX for its slot. The parent component orchestrates layout and logic, while the consumer controls presentation for each section.


Key Takeaway: Multiple render props let you decompose a component into customizable slots, giving consumers surgical control over different parts without sacrificing shared logic or structure.