Created
July 20, 2019 10:21
-
-
Save chathuranga94/c83f72d3f13c7596ac2ec578c1c048dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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