Skip to content

Instantly share code, notes, and snippets.

@thehappybug
Created June 15, 2018 19:21
Show Gist options
  • Save thehappybug/7caaad41309ceac333ce171a4adff418 to your computer and use it in GitHub Desktop.
Save thehappybug/7caaad41309ceac333ce171a4adff418 to your computer and use it in GitHub Desktop.
// This function takes a component...
export function withAppContext(Component) {
// ...and returns another component...
return function ComponentBoundWithAppContext(props) {
// ... and renders the wrapped component with the current context!
// Notice that we pass through any additional props as well
return (
<AppContextConsumer>
{appContext => <Component {...props} appContext={appContext} />}
</AppContextConsumer>
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment