I'm trying to write a generic component that receive a react component and its config.
My generic component should render the react component and apply its corresponding config prop.
For example:
type AProps = {
name: string;
}
type BProps = {
age: number;
}
type CProps = {
address: string;
}
How can I call MyGenericComp with any component (be it AProps or BProps or CProps) so the config will be enforced?
I tried using generics like so:
type MyGenericComp<T extends (_:any) => JSX.Element> = {
component: T;
config: React.ComponentProps<T>;
}
But it doesn't work quite well because I need to define the generic type and it doesn't work with array of MyGenericComp