Skip to content

Instantly share code, notes, and snippets.

@bvodola
Created January 25, 2019 15:11
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 bvodola/a6ba9c7ccc8bcda172e33fac16c8f23f to your computer and use it in GitHub Desktop.
Save bvodola/a6ba9c7ccc8bcda172e33fac16c8f23f to your computer and use it in GitHub Desktop.
// App.js
const App = () =>
<Context.Provider value={this.state.context}>
<AppBar onPressLogoutButton={this.logout} />
<View style={{paddingTop: 64}}>
<Router>
<Route exact path="/" exact component={Home} />
</Router>
</View>
</Context.Provider>
// Context.js
import React from 'react';
const Context = React.createContext();
const withContext = (Component) => {
return (props) =>
<Context.Consumer>
{context => <Component context={context} {...props} />}
</Context.Consumer>
}
export default Context;
export {withContext};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment