I'm trying to implement a HOC in React and TypeScript but am getting a type error.
Here's the HOC:
import * as React from "react";
interface IProps {
loading: boolean;
}
const withLoader = <P extends object>(
Component: React.ComponentType<P>
): React.ComponentType<P & IProps> => ({ loading, ...props }: IProps) =>
loading ? (
<div className="overlay">
<div className="loader" />
</div>
) : (
<Component {...props} />
);
export default withLoader;
The version of the react types are:
"devDependencies": {
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
...
}
The version of react is:
"dependencies": {
"react": "^16.7.0",
"react-dom": "^16.7.0",
...
}
The error I'm getting is:
Type '{}' is not assignable to type 'P'.ts(2322)
Has any one got any ideas?
