liveBook · Manning

ReactNode

As explained in React in Depth

React's exported type representing values that React can render as children, including text, numbers, elements, arrays, and empty values.

ReactNode is React’s exported type for values a component can receive as children. It covers strings, numbers, Booleans, JSX elements, arrays of these values, and omitted children without manually enumerating every case. section 5.3.2

Use ReactNode when a component accepts general-purpose children:

  • Import it as a type from React and mark children optional when the component can render without content. section 5.3.2
  • Prefer ReactNode over a hand-written union when children may include text, numbers, conditional values, JSX elements, or arrays. section 5.3.2
  • Use PropsWithChildren when brevity is preferred; it supplies the same children typing and accepts a generic for additional props. section 5.3.2

A typed heading with additional props

import { type PropsWithChildren } from 'react'; interface HeadingProps { isLarge?: boolean; } function Heading({ isLarge = false, children }: PropsWithChildren<HeadingProps>) { return ( <h1 style={{ backgroundColor: 'hotpink', fontSize: isLarge ? '48px' : '36px' }}> {children} </h1> ); } <Heading isLarge>This is important!</Heading> section 5.3.2

import { type ReactNode } from 'react';
interface HeadingProps {
  children?: ReactNode;
}
function Heading({ children }: HeadingProps) {
  ...
}

The direct ReactNode form makes the children contract explicit while keeping the component implementation unchanged. section 5.3.2

How React in Depth covers it

How deep it goes
Explains the manual union it replaces and contrasts it with PropsWithChildren, stopping short of internal type definitions.
Examples
Uses a Heading component with text, interpolated numbers, conditional values, JSX formatting, omitted children, and an isLarge prop.
What it assumes
Assumes React components and TypeScript props while teaching children typing, optional properties, and generic PropsWithChildren usage.
What you can do after
Apply it via TypeScript to type flexible React children without maintaining a long hand-written union.
How it connects
Connects ReactNode with JSX elements, component props, optional properties, and the PropsWithChildren utility type.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.