Course contentsShow
← React
Lesson 251 of 2,3968. Props PatternsFree lesson

Children Types: Elements, Strings, Numbers

Understanding that children can be JSX elements, plain text, numbers, or any valid React node including arrays.

Children Types: Elements, Strings, Numbers

You'll learn that children isn't just JSX elements — it can be plain text, numbers, or any valid React node.

What Children Can Be

When you pass content between component tags, React doesn't restrict you to only JSX elements. The children prop accepts a surprisingly flexible range of types:

function Card({ children }) {
  return <div className="card">{children}</div>;
}

// JSX elements
<Card><h1>Title</h1></Card>

// Plain text strings
<Card>Just some text</Card>

// Numbers
<Card>{42}</Card>
<Card>{3.14}</Card>

// Multiple mixed types
<Card>
  <h2>Score</h2>
  Your total is: {100}
</Card>

Think of It Like a Box

Imagine children as a delivery box that accepts various contents: wrapped gifts (JSX elements), handwritten notes (strings), or even cash (numbers). React doesn't care what's inside — it just renders whatever you put in.

What Counts as Valid

Any of these work as children:

  • JSX elements: <Button /> or <div>Hello</div>
  • Strings: "Click me" or direct text between tags
  • Numbers: {5} or {count}
  • Arrays of the above (we've seen this with lists)
  • null or undefined (renders nothing)

React automatically converts numbers to strings when rendering, and ignores null/undefined entirely.

Why This Matters

This flexibility means you can create wrapper components that work with any content type, making them incredibly reusable without forcing consumers to wrap everything in extra elements.

Key Takeaway: The children prop accepts JSX elements, strings, numbers, and other valid React nodes — giving you maximum flexibility in what you pass between component tags.