← React Beginner Questions - Set 5 Q49

What is the significance of the children prop in React?

React Beginner Questions - Set 5

`children` is the composition primitive: it lets a component wrap arbitrary content without knowing what it is.

Example

function Panel({ title, actions, children }) {
  return (
    <section className="panel">
      <header>
        <h2>{title}</h2>
        {actions}
      </header>
      <div className="panel__body">{children}</div>
    </section>
  );
}

function App() {
  return (
    <Panel title="Orders" actions={<button>Reload</button>}>
      <p>Anything here arrives as `children`.</p>
      <ul><li>#1001</li><li>#1002</li></ul>
    </Panel>
  );
}

What to notice

← Back to the question list