Skip to content

Instantly share code, notes, and snippets.

@Godefroy
Created March 1, 2020 17:17
Show Gist options
  • Save Godefroy/d43a0bc7beb1d0e3b0d2e97d492e003b to your computer and use it in GitHub Desktop.
Save Godefroy/d43a0bc7beb1d0e3b0d2e97d492e003b to your computer and use it in GitHub Desktop.
const initialState = {
count: 0,
counting: false
}
// Actions
export function reset() {
return { type: 'COUNTER_RESET' }
}
export function increment(n) {
return { type: 'COUNTER_INCREMENT', n }
}
// Reducer
export default function counterReducer(state = initialState, action) {
switch (action.type) {
case 'COUNTER_RESET':
return { ...state, count: 0 }
case 'COUNTER_INCREMENT':
return { ...state, count: state.count + action.n }
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment