import { ComponentType, useContext } from 'react'; import hoistStatics from 'hoist-non-react-statics'; import type { BreakpointKey, BreakpointsProps } from './breakpoints'; import { BreakpointsContext } from './BreakpointsContext'; /** * HOC for providing breakpoints as props * Needs provider for `BreakpointsProps` */ export function withBreakpoints< K extends BreakpointKey = BreakpointKey, P extends BreakpointsProps = BreakpointsProps, >( Component: ComponentType

>, ): ComponentType>> { function WrapperComponent(props: Omit>) { const contextProps = useContext(BreakpointsContext) as BreakpointsProps; return ; } // copy displayname of wrapped component WrapperComponent.displayName = `withBreakpoints(${ Component.displayName || Component.name })`; // copy non-react static properties on the new component return hoistStatics(WrapperComponent, Component); } /** * Pass in the keys of your breakpoints as K */ export type WithBreakpointsProps = BreakpointsProps;