Created
December 11, 2018 18:30
-
-
Save antoniojps/15eac93f7c11ece2febf1ad8e1274a39 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
| // default state | |
| const defaultState = { | |
| welcome: 'Hello', | |
| otherState: 'some stuff', | |
| } | |
| // reducer, always returns new object based on the action type | |
| const greeting = (state = defaultState, action) => { | |
| switch (action.type) { | |
| case 'GREET_ME': | |
| return { | |
| ...state, | |
| welcome: 'Hello Antonio', | |
| } | |
| case 'GREET_WORLD': | |
| return { | |
| ...state, | |
| welcome: 'Hello World', | |
| } | |
| default: | |
| return state | |
| } | |
| } | |
| // creates store from reducers | |
| const store = createStore(greeting) | |
| console.log(store.getState()) | |
| // {welcome: "Hello", otherState: "some stuff"} | |
| // action is an object describing what we are dispatching | |
| store.dispatch({ | |
| type: 'GREET_ME' | |
| }) | |
| console.log(store.getState()) | |
| // {welcome: "Hello Antonio", otherState: "some stuff"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment