means that you’re trying to render a value in a React component that is not a valid React child. ReactNode is a type that includes anything that can be rendered: JSX elements, strings, numbers, null, undefined, booleans, etc.
❌ Example:
const myObj = { name: 'Prem' };
return myObj; // ❌ Error: object is not a valid ReactNode
Fix:
return
;
❌ Example:
const MyComponent = () => {
return () =>
; // ❌ returning a function
}
Fix:
const MyComponent = () => {
return
;
}
❌ Example:
const items = [{ id: 1 }, { id: 2 }];
return <>{items}>; // ❌ Object is not a ReactNode
Fix:
return (
<>
{items.map(item =>
)}
>
);
If you’re passing props and TypeScript expects ReactNode but receives something else:
type MyProps = {
children: ReactNode;
}
const MyComponent = ({ children }: MyProps) =>
;
Ensure you pass valid children:
âś… Correct Usage:
Hello
If you’re unsure what X is in the error Type ‘X’ is not assignable to type ‘ReactNode’, hover over X in your IDE or use console.log(typeof X) to inspect it.
Work with our skilled Node developers to accelerate your project and boost its performance.
Hire Node.js Developers