Skip to content

Instantly share code, notes, and snippets.

@CatherineThompson
Forked from thehappybug/AppContext.tsx
Created May 27, 2020 05:17
Show Gist options
  • Select an option

  • Save CatherineThompson/5561a0da4ee7fc659705454653390dd1 to your computer and use it in GitHub Desktop.

Select an option

Save CatherineThompson/5561a0da4ee7fc659705454653390dd1 to your computer and use it in GitHub Desktop.
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export function withAppContext<
P extends { appContext?: AppContextInterface },
R = Omit<P, 'appContext'>
>(
Component: React.ComponentClass<P> | React.StatelessComponent<P>
): React.SFC<R> {
return function BoundComponent(props: R) {
return (
<AppContextConsumer>
{value => <Component {...props as unknown as P} appContext={value} />}
</AppContextConsumer>
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment