Last active
January 29, 2020 15:35
-
-
Save dominictobias/70074f2ab0146b288e3801258c6cdc41 to your computer and use it in GitHub Desktop.
appState
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
const darkTheme = { | |
name: 'dark', | |
background: 'black', | |
text: 'white', | |
} | |
const lightTheme = { | |
name: 'light', | |
background: 'white', | |
text: 'black', | |
} | |
function reducer(state, actionName, payload) { | |
switch (actionName) { | |
case 'toggleTheme': | |
return { | |
...state, | |
theme: state.theme.name === 'light' ? darkTheme : lightTheme, | |
}; | |
default: | |
throw new Error(`Action does not exist: ${actionName}`); | |
} | |
} | |
const appState = new GlobalState(reducer, { theme: lightTheme }); | |
export default appState; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part of https://medium.com/@dominictobias/using-react-hooks-for-global-redux-stores-97c092afe210 article