import { type ComponentType, type JSX } from 'react';

type ContextProvider = <T extends object>(props: T) => JSX.Element;

export function withContext<T extends object>(ContextProvider: ContextProvider) {
  return function <P extends T>(Component: ComponentType<P>) {
    return (props: P) => {
      return (
        <ContextProvider {...props}>
          <Component {...props} />
        </ContextProvider>
      );
    };
  };
}
