Created
July 29, 2019 18:25
-
-
Save chathuranga94/dcaf1cdf3cb6d0e4f6b095fa7f5fad00 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'; | |
import { GlobalStoreProvider, GlobalStore } from 'global-store-hook'; | |
const App = () => { | |
const init = { | |
lang: 'en', | |
color: 'blue' | |
} | |
return ( | |
<GlobalStoreProvider initValues={init}> | |
<LanguagePicker /> | |
<Menu /> | |
</GlobalStoreProvider> | |
); | |
} | |
const Menu = () => <MenuItem />; | |
const LanguagePicker = () => { | |
const store = GlobalStore(); | |
return ( | |
<div> | |
<button onClick={() => store.set('lang', 'en')}>English</button> | |
<button onClick={() => store.set('lang', 'fr')}>French</button> | |
</div> | |
); | |
} | |
const MenuItem = () => { | |
const store = GlobalStore(); | |
return ( | |
<div> | |
<p>Theme colour: {store.get('color')}</p> | |
<p>Locale: {store.get('lang')}</p> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment