Skip to content

Instantly share code, notes, and snippets.

@Arjun-sna
Last active Jun 24, 2018
Embed
What would you like to do?
Gist to create reducer in redux
export function createReducer(reducerMap, defaultState) {
return (state = { ...defaultState }, action) => reducerMap.hasOwnProperty(action.type) ? reducerMap[action.type](state, action) : state;
}
// Sample usage
posts: createReducer({
[ALL_POSTS_RECEIVED]: (state, action) => {
//do something
},
[POSTS_REQUEST_IN_PROGRESS]: (state, action) => {
//do something
}
}, { posts: [], moreDataAvailable: true }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment