To make JSX.Element properties of Typescript compatible with ComponentType type, you can do the following:
import { ComponentType } from 'react';
type CustomProps = {
myProp: string;
};
function CustomComponent(props: CustomProps) {
...
}
const MyComponent: ComponentType<CustomProps> = CustomComponent;
function ParentComponent() {
return <ChildComponent myComponent={MyComponent} />;
}
function ChildComponent(props: { myComponent: ComponentType<CustomProps> }) {
const MyComponent = props.myComponent;
return <MyComponent myProp="Hello world" />;
}
Asked: 2022-06-06 11:00:00 +0000
Seen: 7 times
Last updated: Feb 22 '22