Backbencher.dev

Type of React props.children in TypeScript

Last updated on 3 Mar, 2023

In TypeScript, the type of props.children depends on the usage.

If props.children is expected to be a single React element, the type can be specified as React.ReactNode.

If props.children is expected to be an array of React elements, the type can be specified as React.ReactNodeArray.

For example, consider the following functional component:

interface Props {
  children: React.ReactNode;
}

function MyComponent(props: Props) {
  return <div>{props.children}</div>;
}

Here, props.children is expected to be a single React element, and its type is specified as React.ReactNode.

--- ○ ---
Joby Joseph
Web Architect