ReactElement: Only JSX Elements
What you'll learn: How ReactElement differs from ReactNode by strictly accepting only JSX elements, excluding primitives and null/undefined.
The Stricter Type
While ReactNode accepts almost anything that React can render (strings, numbers, booleans, null, undefined, arrays, fragments, and JSX elements), ReactElement is much pickier. It only accepts actual JSX elements—the result of JSX expressions like <div /> or <MyComponent />.
Think of it like this: ReactNode is a grocery bag that accepts any food item, while ReactElement is a container that only accepts items still in their original packaging—no loose fruit allowed.
When to Use ReactElement
Use ReactElement when your component specifically requires a JSX element and shouldn't accept primitives:
interface TabsProps {
header: ReactElement; // Must be <TabHeader /> or similar
children: ReactNode; // Can be anything
}
function Tabs({ header, children }: TabsProps) {
return (
<div>
{header}
{children}
</div>
);
}
// ✅ Valid
<Tabs header={<TabHeader />}>Content here</Tabs>
// ❌ TypeScript error
<Tabs header="Just a string">Content</Tabs>
// ❌ TypeScript error
<Tabs header={null}>Content</Tabs>
Why This Matters
ReactElement gives you compile-time guarantees that you're receiving actual components, not primitive values. This prevents bugs where you might try to clone an element, access its props, or perform other JSX-specific operations that would fail on strings or numbers.
Key Takeaway: Use ReactElement when you need to enforce that a prop is specifically a JSX element—not a string, number, or nullish value—providing stricter type safety than ReactNode.