Frontend

The React children Prop: Composition Patterns With Real Examples

children props
On this page
  1. What the React children prop is
  2. Pattern 1: Wrapper components
  3. Pattern 2: Named slots with regular props
  4. Pattern 3: Composition instead of prop drilling
  5. Pattern 4: Function as children
  6. Pattern 5: Inspecting children with the Children helpers
  7. Common mistakes
  8. TypeScript types for children
  9. A free performance win: children don’t re-render
  10. children with Server Components
  11. Which pattern should you use?
  12. Frequently asked questions about the React children prop
  13. Oh hi there 👋It’s nice to meet you.
  14. Sign up to receive awesome content in your inbox.

Most React components you write receive data through props: a title, a price, a user. The special children prop works differently: it receives the content you put between a component’s opening and closing tags. It is the key to building components that wrap other content, such as cards, layouts, modals and buttons, without knowing in advance what that content will be. This guide explains the React children prop and the patterns built on it, with every example rendered in a browser on React 19.

What the React children prop is

How the children prop works in ReactWhatever you place between a component’s opening and closing tags is passed to it as props.children, and the component decides where to render it.You write<Card>…</Card>React passesprops.childrenelements, text, functionsCard renders{children}wherever it choosesResultcontent in the card
Content between a component’s tags arrives as props.children; the component decides where it goes.
function Card({ title, children }) {
  return (
    <section className="card">
      <h2>{title}</h2>
      {children}
    </section>
  );
}

<Card title="Profile">
  <p>Aarav from Pune</p>
</Card>

React passes the paragraph to Card as props.children, and Card places it under its heading. In testing, the page rendered “Aarav from Pune” inside the card. The card controls its frame and style; the caller controls the content. That separation is why the same Card can wrap a profile, a form or a chart.

children can be anything React can render: text, elements, several elements, arrays from map(), or nothing. It can also be something React can’t render directly, such as a function, which is a pattern shown below.

Pattern 1: Wrapper components

The most common use: components that add structure or behaviour around content.

function Modal({ open, onClose, children }) {
  if (!open) return null;
  return (
    <div className="backdrop" onClick={onClose}>
      <div className="modal" role="dialog" aria-modal="true" onClick={(e) => e.stopPropagation()}>
        {children}
        <button onClick={onClose}>Close</button>
      </div>
    </div>
  );
}

<Modal open={isOpen} onClose={() => setIsOpen(false)}>
  <h2>Delete this order?</h2>
  <p>This can’t be undone.</p>
</Modal>

The modal handles the backdrop, accessibility attributes and closing; each use supplies its own message. Layouts, buttons with icons, form fields with labels and error messages, and permission guards all follow this shape.

Pattern 2: Named slots with regular props

One children prop covers one area. When a component has several areas, pass the others as ordinary props, which can hold elements too:

function Layout({ sidebar, footer, children }) {
  return (
    <div className="layout">
      <aside>{sidebar}</aside>
      <main>{children}</main>
      {footer && <footer>{footer}</footer>}
    </div>
  );
}

<Layout sidebar={<Filters />} footer={<Pagination />}>
  <ProductGrid />
</Layout>

In testing, the sidebar rendered “Filters” and the main area rendered “Products”, each in its own slot. Using children for the main content and named props for the rest keeps calls readable.

Pattern 3: Composition instead of prop drilling

Prop drilling means passing a value through several components that don’t use it, just to reach one that does. Composition with children often removes the need entirely:

// ❌ drilling: Page passes user through Layout and Header just to reach Avatar
<Page user={user} />

// ✅ composition: Page builds the avatar where the user is known
function Page({ user }) {
  return (
    <Layout header={<Header avatar={<Avatar user={user} />} />}>
      <Dashboard />
    </Layout>
  );
}

Layout and Header no longer need to know about user at all. Reach for context only when many distant components need the same value; composition is simpler and makes data flow easy to follow.

Pattern 4: Function as children

Sometimes a component owns some data and wants the caller to decide how to display it. The caller passes a function as children, and the component calls it:

function WithUser({ children }) {
  const user = { name: 'Aarav' };          // could come from an API or a hook
  return children({ user });
}

<WithUser>
  {({ user }) => <p>Hello {user.name}</p>}
</WithUser>

This rendered “Hello Aarav” in testing. The pattern, also called a render prop, was common before hooks. Today a custom hook such as useUser() is usually simpler, but you will meet function-as-children in libraries for forms, animations and virtualized lists.

Pattern 5: Inspecting children with the Children helpers

Occasionally a component needs to work with its children individually, for example a tab set that shows one panel at a time. React provides helpers in the Children object:

import { Children, useState } from 'react';

function Tabs({ children }) {
  const [active, setActive] = useState(0);
  const tabs = Children.toArray(children);
  return (
    <div>
      <nav>
        {tabs.map((tab, i) => (
          <button key={i} onClick={() => setActive(i)}>{tab.props.label}</button>
        ))}
      </nav>
      {tabs[active]}
    </div>
  );
}

<Tabs>
  <Tab label="One">First panel</Tab>
  <Tab label="Two">Second panel</Tab>
</Tabs>

In testing, the first panel showed initially and clicking the second button switched to “Second panel”. One subtle difference between helpers showed up clearly: for children made of 'a', null, false and an array of two strings, Children.count returned 5 but Children.toArray returned 3 items, because toArray drops null and false. Use toArray when you mean “the things that will actually render”.

The React documentation treats these helpers, along with cloneElement, as legacy APIs: they make components fragile, because they depend on the exact structure of their children. Prefer passing data as props, for example <Tabs items={[{ label, content }]} />, when you control both sides.

Common mistakes

  • Forgetting to render {children}. If the component never places it, the content silently disappears.
  • Rendering an object as children. Passing an object, or a Date, causes “Objects are not valid as a React child”; see that error explained.
  • Calling children as a function when it isn’t one. Check with typeof children === 'function' if a component supports both forms.
  • Assuming children is always an array. A single child is not wrapped in an array, so use Children.toArray before calling array methods.

TypeScript types for children

import type { ReactNode } from 'react';

type CardProps = { title: string; children: ReactNode };
function Card({ title, children }: CardProps) { … }

type WithUserProps = { children: (data: { user: User }) => ReactNode };

ReactNode accepts everything React can render, and TypeScript then rejects invalid children, such as plain objects, while you type.

A free performance win: children don’t re-render

Passing content as children has a performance benefit that many developers don’t know about. When a wrapper component updates its own state, elements it received as children are not rendered again, because they were created by the parent, which didn’t change. A test made this visible. A wrapper tracked mouse movement in state, updating 10 times, and contained an expensive component in two different ways:

How the expensive component was placed Times it rendered
Written inside the wrapper’s own JSX 11 (once, plus once per update)
Passed to the wrapper as children 1
// re-renders Expensive on every mouse move
function HoverBox() {
  const [moves, setMoves] = useState(0);
  return <div onMouseMove={() => setMoves(moves + 1)}><Expensive /></div>;
}

// Expensive renders once: it arrives as children from the parent
function HoverBox({ children }) {
  const [moves, setMoves] = useState(0);
  return <div onMouseMove={() => setMoves(moves + 1)}>{children}</div>;
}
<HoverBox><Expensive /></HoverBox>

This “lift content up” technique often fixes slow components without React.memo. Whenever a component has fast-changing state, such as scroll position, mouse position or an animation, move the content that doesn’t depend on that state out to the parent and pass it in as children.

children with Server Components

In frameworks with React Server Components, such as the Next.js App Router, children is how server and client code mix. A Client Component, such as an interactive accordion, can receive Server Components as children: the server renders them, and the client component only arranges them. This keeps data fetching on the server and only the interactive part in the browser bundle. The model is explained in React Server Components explained.

Which pattern should you use?

Start with plain children for any component that wraps content. Add named props such as header or sidebar when there are several areas. Use a function as children only when the component owns data the caller must render. Reach for the Children helpers last, when nothing else fits, because they tie a component to the exact shape of what it receives.

Frequently asked questions about the React children prop

Is children a reserved prop in React?

It is a normal prop with special syntax: content between the tags is assigned to it. You can also pass it explicitly, <Card children={…} />, though the tag form is clearer.

Can a component have more than one children area?

Not through children alone, but you can pass extra areas as named props, such as sidebar or footer, which also accept elements.

Should I use Children.map or array map?

For data you control, map over an array of data. Use Children.toArray or Children.map only when a component must work with JSX children it receives from outside.

Is the render prop pattern still useful?

Less often since hooks. A custom hook usually shares logic more simply, but render props still appear in libraries and are useful when a component must control what renders around the caller’s output.

Do children re-render when the parent re-renders?

Yes, when the component that created them re-renders. When only the wrapper that receives them updates its own state, they don’t, which is a useful way to avoid unnecessary renders.

Why is my component’s content not showing?

The component probably doesn’t render {children} anywhere. Content placed between a component’s tags only appears where the component outputs the children prop.

Can children be a string?

Yes. <Button>Save</Button> passes the string “Save” as children, and rendering {children} shows it.

logo

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox.

We don’t spam! Read our privacy policy for more info.

Saurabh

Saurabh Pathak is an AI engineer and MERN stack developer, and the founder of mernstackdev.com. He builds open-source projects such as the Haat gateway and MCP safety tooling, and he writes hands-on tutorials on React, Node.js, MongoDB and AI agents. He cares most about code that works in production.