how do i define reactnode as a prop for a typescript react component?

You are confusing props type with variable type. What you have actually done here:

= ({ Comp = MyComponent }: React.FC<{
  Comp: React.ReactNode;
}>)

basically you told TS that the props object is a React.FC, which obviously isn’t.

So either move the type just right after variable declaration:

const MyComponent2: React.FC<{
   Comp: React.ReactNode;
}> = ({ Comp = MyComponent }) => (

or just remove the React.FC:

const MyComponent2 = ({ Comp = MyComponent }: {
   Comp: React.ReactNode;
}) => (

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top