Created
June 29, 2019 19:28
-
-
Save jsmanifest/e9e7bef95dd2de8a6cd13e325358baa1 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
| const something = (state) => { | |
| let newState = { ...state } | |
| const indexPanda = newState.items.indexOf('panda') | |
| if (indexPanda !== -1) { | |
| newState.items.splice(indexPanda, 1) | |
| } | |
| return newState | |
| } | |
| const initialState = { | |
| items: [], | |
| } | |
| const reducer = (state, action) => { | |
| switch (action.type) { | |
| case 'add-item': | |
| return { ...state, items: [...something(state).items, action.item] } | |
| case 'clear': | |
| return { ...initialState } | |
| default: | |
| return state | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment