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 ( |
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, { useContext, useReducer } from 'react'; | |
const AppContext = React.createContext({}); | |
const App = () => { | |
let initialState = { lang: 'en', color: 'blue'}; | |
let reducer = (state, action) => { | |
switch (action.type) { | |
case "change-language": |
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, { useState, useContext } from 'react'; | |
const AppContext = React.createContext({}); | |
const App = () => { | |
const [lang, setLang] = useState('en'); | |
const [color, setColor] = useState('blue'); | |
const store = { | |
lang: { get: lang, set: setLang }, |
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'; | |
class App extends React.Component { | |
state = { lang: 'en', color: 'blue' } | |
changeLanguage = (lang) => { | |
this.setState({...this.state, lang: lang}); | |
} | |
render() { |
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 { globalStore } from './global'; | |
const languages = { en: 'en', fr: 'fr' }; | |
const { Provider: AppProvider, Consumer: AppConsumer } = React.createContext({}); | |
const App = () => { | |
const init = { lang: 'en', color: 'blue', count: 20 } |
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 { globalStore } from './global'; | |
const languages = { en: 'en', fr: 'fr' }; | |
const { Provider: AppProvider, Consumer: AppConsumer } = React.createContext({}); | |
const App = () => { | |
const init = { lang: 'en', color: 'blue', count: 20 } |
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, { useState } from 'react'; | |
const languages = { en: 'en', fr: 'fr' }; | |
const initialTheme = { colour: 'blue', lang: languages.en, setLanguage: () => {} }; | |
const { Provider: AppProvider, Consumer: AppConsumer } = React.createContext(initialTheme); | |
const App = () => { | |
const setLanguage = (lang) => { | |
setTheme({ ...theme, lang: lang }); |
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, { useState } from 'react'; | |
const languages = { en: 'en', fr: 'fr' }; | |
const initialTheme = { colour: 'blue', lang: languages.en }; | |
const { Provider: AppProvider, Consumer: AppConsumer } = React.createContext(initialTheme); | |
const App = () => { | |
const [theme, setTheme] = useState(initialTheme); |
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() { |
NewerOlder