import React from "react" ; import { hoistStatics , InferableComponentEnhancer , wrapDisplayName , } from "recompose" ; /**
 * withContext is a HOC wrapper around `CoralContextConsumer`.
 * `propsCallback` must be provided which accepts the `CoralContext`
 * and returns the props the should be injected.
 */ function createContextHOC < Context > ( displayName , Consumer ) { return function withContext < T > ( propsCallback ) : InferableComponentEnhancer < T > { return hoistStatics < T > ( < U extends T > ( WrappedComponent ) => { const Component = ( props ) => ( < Consumer > { ( context ) => ( < WrappedComponent { ... props } { ... propsCallback ( context ) } / > ) } < /Consumer>); Component . displayName = wrapDisplayName ( WrappedComponent , displayName ) ; return Component as any ; } ) ; } ; } export default createContextHOC ;