Skip to content

Instantly share code, notes, and snippets.

@noblesilence
Created October 27, 2019 07:13
Show Gist options
  • Save noblesilence/5fba550034949efa16f90f06b13efc38 to your computer and use it in GitHub Desktop.
Save noblesilence/5fba550034949efa16f90f06b13efc38 to your computer and use it in GitHub Desktop.
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