bigbuffet-rw/app/soapbox/components/hoc/with-hoc.tsx

11 lines
389 B
TypeScript
Raw Normal View History

2023-04-17 11:56:31 -07:00
type HOC<P, R> = (Component: React.ComponentType<P>) => React.ComponentType<R>
type AsyncComponent<P> = () => Promise<{ default: React.ComponentType<P> }>
const withHoc = <P, R>(asyncComponent: AsyncComponent<P>, hoc: HOC<P, R>) => {
return async () => {
const { default: component } = await asyncComponent();
return { default: hoc(component) };
};
};
export default withHoc;