import * as React from 'react';
import hoistStatics from 'hoist-non-react-statics';
import {NonReactStatics} from '@shopify/useful-types';
export type ReactComponent
= React.ComponentType
;
export type ComponentClass = React.ComponentClass;
export type WrappingFunction = (
Component: ReactComponent,
) => ReactComponent;
export default function compose(
...wrappingFunctions: WrappingFunction[]
) {
return function wrapComponent(
OriginalComponent: ReactComponent & C,
): ReactComponent & NonReactStatics {
const result: ReactComponent = wrappingFunctions.reduceRight(
(component: ReactComponent, wrappingFunction: WrappingFunction) =>
wrappingFunction(component),
OriginalComponent,
);
return hoistStatics(
result as ComponentClass,
OriginalComponent as ComponentClass,
) as ReactComponent & NonReactStatics;
};
}