Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Created November 20, 2018 14:54
Show Gist options
  • Save joshuacerbito/325b31ee2659e2cc698e234ab010ebe7 to your computer and use it in GitHub Desktop.
Save joshuacerbito/325b31ee2659e2cc698e234ab010ebe7 to your computer and use it in GitHub Desktop.
Higher Order Component for handling React's Context consumer outside of a component's render function
import React from "react";
const WithContext = (Component, Context) => {
return props => (
<Context.Consumer>
{value => <Component {...props} context={value} />}
</Context.Consumer>
);
};
export default WithContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment