Vencovsky
Vencovsky

Reputation: 31605

What is the correct type for a prop that can be used in jsx?

I have a prop that I will use JSX on it, and I need to define it's type.

interface CustomComponentProps {
    Component: // What should I put here?
}

const CustomComponent = ({ Component }: CustomComponentProps) => {
    // some other stuff

    return <Component someProp={foo} />
}

What is the type for a prop that can be used with jsx?

Upvotes: 0

Views: 73

Answers (1)

cbr
cbr

Reputation: 13642

You can use React.ComponentType<T> which accepts both React.FC and React.Component:

interface CustomComponentProps {
    Component: React.ComponentType<{ someProp: string }>
}

Upvotes: 1

Related Questions