What is the type of the children prop in React with TypeScript?
Hi everyone! I just started learning React with TypeScript, and I have a problem with typing the `children` prop.
I have a simple wrapper component:
```tsx
interface CardProps {
title: string;
children: ???; // What to write here?
}
function Card({ title, children }: CardProps) {
return (
);
}
```
I want this component to be able to accept:
1. Simple text (string)
2. Another React component
3. Multiple components wrapped in a fragment
4. Any JSX elements (div, span, img, etc.)
5. Even null or undefined (if children is not passed)
In JavaScript I just wrote `children: any`, but in TypeScript this is considered bad
{title}
{children}
No answers yet.
Log in to leave an answer
Blogs