Created
March 1, 2020 17:17
-
-
Save Godefroy/d43a0bc7beb1d0e3b0d2e97d492e003b 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 = { | |
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