Created
October 27, 2019 07:13
-
-
Save noblesilence/5fba550034949efa16f90f06b13efc38 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 initialState = { | |
counter: 0 | |
} | |
const reducer = (state = initialState, action) => { | |
if (action.type === 'INCREMENT') { | |
return { | |
counter: state.counter + 1 | |
} | |
} | |
if (action.type === 'DECREMENT') { | |
return { | |
counter: state.counter - 1 | |
} | |
} | |
if (action.type === 'ADD') { | |
return { | |
counter: state.counter + 5 | |
} | |
} | |
if (action.type === 'SUBSTRACT') { | |
return { | |
counter: state.counter - 5 | |
} | |
} | |
return state; | |
} | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment