Question
I have a simple React functional component in TypeScript:
import * as React from 'react';
export interface AuxProps {
children: React.ReactNode;
}
const Aux = (props: AuxProps) => props.children;
export default Aux;
And another component:
import * as React from 'react';
export interface LayoutProps {
children: React.ReactNode;
}
const Layout = (props: LayoutProps) => (
<Aux>
<div>Toolbar, SideDrawer, Backdrop</div>
<main>{props.children}</main>
<Aux/>
);
export default Layout;
I get this TypeScript error:
JSX element type 'ReactNode' is not a constructor function for JSX elements.
Type 'undefined' is not assignable to type 'ElementClass'. [2605]
How should children be typed correctly in React with TypeScript, and why does this error happen?
Short Answer
By the end of this page, you will understand what the children prop represents in React, when to use React.ReactNode, why a component cannot directly return just any ReactNode type in some TypeScript setups, and how to type wrapper components correctly using React.ReactNode, JSX.Element, or React.FC patterns.
Concept
What children means in React
In React, children is the content placed between a component's opening and closing tags.
<Aux>
<div>Hello</div>
</Aux>
Here, the <div>Hello</div> part becomes the children prop of Aux.
The correct type for children
In TypeScript, the most common type for children is:
React.ReactNode
React.ReactNode is a broad type that includes:
- React elements
- strings
- numbers
- fragments
- arrays of nodes
nullundefined- booleans
That makes it a good type for , because React allows all of these to be rendered.
Mental Model
Think of children as the contents of a box.
- The component is the box.
- Anything placed inside the box becomes
children. React.ReactNodemeans "almost anything React knows how to display can go in this box."
Now think about the component's return value as what the factory is allowed to ship out.
childrencan be many different things.- But a JSX component is usually expected to return a proper React element or
null. - If TypeScript sees that your component might return
undefined, it says, "This is not a reliable JSX component."
So:
childrentype answers: What can go inside?- return type answers: What does the component produce?
Syntax and Examples
Basic children prop typing
type Props = {
children: React.ReactNode;
};
function Wrapper({ children }: Props) {
return <div>{children}</div>;
}
This is the most common pattern.
Corrected version of your example
import * as React from 'react';
type AuxProps = {
children: React.ReactNode;
};
const Aux = ({ children }: AuxProps): JSX.Element => {
return <>{children}</>;
};
export default Aux;
Why this works
Step by Step Execution
Trace through a small example
type BoxProps = {
children: React.ReactNode;
};
function Box({ children }: BoxProps): JSX.Element {
return <section>{children}</section>;
}
function App(): JSX.Element {
return (
<Box>
<p>Hello</p>
</Box>
);
}
What happens step by step
1. App renders
React sees:
<Box>
<p>Hello</p>
</Box>
Real World Use Cases
Layout wrappers
A layout component often wraps pages and renders shared UI around page content.
<Layout>
<Dashboard />
</Layout>
Modal components
A modal usually accepts any content as children.
<Modal>
<form>...</form>
</Modal>
Card and panel components
Reusable UI containers often render children inside a styled box.
<Card>
<p>Profile details</p>
</Card>
Context providers
Providers typically wrap part of the app and render descendant components through children.
<AuthProvider>
</>
Real Codebase Usage
Common patterns developers use
Wrapper components
The most common pattern is a wrapper that accepts children and returns JSX:
type Props = {
children: React.ReactNode;
};
function Container({ children }: Props) {
return <div className="container">{children}</div>;
}
Guard clauses
Sometimes a component only renders when children exists.
function MaybeWrap({ children }: { children?: React.ReactNode }) {
if (!children) return null;
return <div>{children}</div>;
}
Validation and fallback UI
Common Mistakes
1. Returning children directly when the inferred type is too broad
Broken example:
const Aux = (props: { children: React.ReactNode }) => props.children;
Why it can fail:
- TypeScript may infer the return type as
React.ReactNode ReactNodecan includeundefined- JSX components are often expected to return
JSX.Elementornull
Fix:
const Aux = ({ children }: { children: React.ReactNode }): JSX.Element => {
return <>{children}</>;
};
2. Mistyping the closing tag
Broken example:
<Aux>
Comparisons
Related type choices
| Type | What it means | Good for children? | Notes |
|---|---|---|---|
React.ReactNode | Anything React can render | Yes | Most common choice |
JSX.Element | A single JSX element | Sometimes | Too narrow for many children cases |
React.ReactElement | A React element object | Sometimes | Similar to JSX.Element, still narrower than ReactNode |
string | Text only |
Cheat Sheet
Quick reference
Type children
type Props = {
children: React.ReactNode;
};
Optional children
type Props = {
children?: React.ReactNode;
};
Safe wrapper component
function Wrapper({ children }: { children: React.ReactNode }): JSX.Element {
return <>{children}</>;
}
With other props
type CardProps = {
title: string;
children: React.ReactNode;
};
With
FAQ
What is the correct TypeScript type for React children?
Usually React.ReactNode. It covers most values React can render, including elements, strings, numbers, fragments, null, and arrays.
Why does returning props.children directly cause an error?
Because children is typed as ReactNode, and that type can include undefined. Some TypeScript React setups require JSX components to return a JSX element or null.
Should I use JSX.Element for children?
Usually no. JSX.Element is narrower and only allows a single JSX element. React.ReactNode is more flexible.
Is React.FC required to type children?
No. You can type props explicitly. React.FC is optional.
When should children be optional?
Make it optional when the component should still work without inner content.
Mini Project
Description
Build a reusable Card wrapper component that accepts a title and displays any nested content using the children prop. This demonstrates the most common real-world use of children: creating reusable layout and UI wrapper components.
Goal
Create a typed React component that safely accepts children and renders it inside a styled wrapper.
Requirements
- Create a
Cardcomponent with a requiredtitleprop. - Type the nested content using
React.ReactNode. - Return valid JSX from the component.
- Render the component with different kinds of children, such as text and elements.
Keep learning
Related questions
Angular formGroup Error Explained: Fixing 'Can't bind to formGroup' in Reactive Forms
Learn why Angular shows 'Can't bind to formGroup' and how to fix it by importing ReactiveFormsModule correctly.
Fix "Element implicitly has an 'any' type" in TypeScript Object Indexing
Learn why TypeScript rejects string object indexing and how to fix it with keyof, unions, and typed object keys in React.
Fix "Property has no initializer" in Angular TypeScript Components
Learn why Angular TypeScript shows "Property has no initializer" and how to fix it using defaults, optional properties, or definite assignment.