Skip to content

Instantly share code, notes, and snippets.

@chathuranga94
Created July 20, 2019 10:21
Show Gist options
  • Save chathuranga94/c83f72d3f13c7596ac2ec578c1c048dd to your computer and use it in GitHub Desktop.
Save chathuranga94/c83f72d3f13c7596ac2ec578c1c048dd to your computer and use it in GitHub Desktop.
import React from 'react';
const AppContext = React.createContext({ colour: 'blue', lang: 'en' });
const App = () =>
<AppContext.Provider value={{ colour: 'blue', lang: 'fr' }}>
<Menu />
</AppContext.Provider>;
function Menu() {
return <MenuItem />
}
const MenuItem = () =>
<AppContext.Consumer>
{ value =>
<div>
<p>Theme colour: {value.colour}</p>
<p>Locale: {value.lang}</p>
</div>
}
</AppContext.Consumer>
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment