Skip to content

Instantly share code, notes, and snippets.

@kitze
Created January 5, 2016 12:43
Show Gist options
  • Save kitze/7e65eede3208e12ba021 to your computer and use it in GitHub Desktop.
Save kitze/7e65eede3208e12ba021 to your computer and use it in GitHub Desktop.
redux action without switch
import * as types from '../actions/actionTypes';
const initialState = {
count: 0
};
export default counter = (state = initialState, action = {}) => {
return {
[types.INCREMENT]: {
...state,
count: state.count + 1
},
[types.DECREMENT]: {
...state,
count: state.count - 1
}
}[action.type] || state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment