Skip to content

Instantly share code, notes, and snippets.

@deniztetik
Created July 8, 2018 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deniztetik/e064dacdb583dbdbd76982e1eda3ecf7 to your computer and use it in GitHub Desktop.
Save deniztetik/e064dacdb583dbdbd76982e1eda3ecf7 to your computer and use it in GitHub Desktop.
// ./src/index.js
// imports
const AppContext = React.createContext();
export function withContext(Component){
return (props) => (
<AppContext.Consumer>
{contextProps =>
/* override contextprops with specific name
if prop of same name is manually added */
<Component {...contextProps } {...props} />
}
</AppContext.Consumer>
);
}
// App component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment