import React from 'react'; export default function(Context: React.Context, shouldRender: (context: CP) => boolean = () => true) { return function

(WrappedComponent: React.ComponentType

) { type WrappedComponentProps = Omit, keyof CP>; type WrappedComponentPropsWithForwardRef = WrappedComponentProps & { forwardRef: React.Ref; }; const InjectContext: React.FC = props => { const { forwardRef, ...rest } = props; let refProp = {}; if (WrappedComponent.prototype.isReactComponent) { refProp = { ref: forwardRef, }; } else { refProp = { forwardRef, }; } return ( {context => shouldRender(context) ? : null } ); }; return React.forwardRef((props, ref) => ); }; }