ReactNode: The Broadest Children Type
You'll learn why ReactNode is TypeScript's most flexible type for anything a component can render as children.
What ReactNode Accepts
When you need to type children that might be anything renderable, ReactNode is your answer. It's React's union type that encompasses every valid thing you can render:
- Strings and numbers:
"Hello",42 - JSX elements:
<div>...</div> - Fragments:
<>...</> - Arrays:
[<li key="1">Item</li>, ...] - null and undefined: for conditional rendering
- Booleans: (ignored by React, but valid)
- Other ReactNodes: nested children
Think of ReactNode as the "accepts everything renderable" type—the broadest net you can cast.
When to Use ReactNode
Use ReactNode when your component doesn't care what gets rendered, only that something might be:
interface CardProps {
children: ReactNode;
title: ReactNode; // Could be string OR JSX
}
function Card({ children, title }: CardProps) {
return (
<div>
<h2>{title}</h2>
{children}
</div>
);
}
// All valid:
<Card title="Plain text">Hello</Card>
<Card title={<strong>Bold</strong>}>{42}</Card>
<Card title="Mixed">{null}</Card>
Why Not Just Use PropsWithChildren?
PropsWithChildren<T> specifically types the children prop, while ReactNode can type any prop that accepts renderable content—like title, header, footer, or custom render props.
Key Takeaway: ReactNode is the go-to type for any prop that accepts renderable content—use it when you need maximum flexibility for strings, JSX, numbers, or conditional null/undefined values.