I am new to TypeScript and I am struggling to write HOC with typecheck. Here's my HOC:
import React from 'react';
import Firebase from './Firebase';
export type FirebaseType = Firebase;
interface OwnProps {
firebase: typeof Firebase;
}
const FirebaseContext = React.createContext(new Firebase());
export const withFirebase: React.FC = <T extends OwnProps>(
Component: React.ComponentType<T>,
): React.ComponentType<T> => (props) => (
<FirebaseContext.Consumer>
{(firebase: FirebaseType) => <Component {...props} firebase={firebase} />}
</FirebaseContext.Consumer>
);
export default FirebaseContext;
It throws an error:
Type '(Component: React.ComponentType) => React.ComponentType' is not assignable to type 'FC<{}>'. Types of parameters 'Component' and 'props' are incompatible. Type '{ children?: ReactNode; }' is not assignable to type 'ComponentType'. Type '{ children?: ReactNode; }' is not assignable to type 'FunctionComponent'. Type '{ children?: ReactNode; }' provides no match for the signature '(props: PropsWithChildren, context?: any): ReactElement ReactElement Component)> | null) | (new (props: any) => Component<...>)> | null'.ts(2322)
I have absolutely no idea how to move on with this code or how to make it work.
Any thoughts?