Skip to content

Instantly share code, notes, and snippets.

@smks
Last active December 2, 2018 13:08
Show Gist options
  • Save smks/6e16a326a253b24c44880591a7755d53 to your computer and use it in GitHub Desktop.
Save smks/6e16a326a253b24c44880591a7755d53 to your computer and use it in GitHub Desktop.
Handle actions equivalent of reducer
import { handleActions } from 'redux-actions';
import { getPeople } from '../actions';
const INITIAL_STATE = {
hasLoadedPeople: false,
errorGettingPeople: false,
list: [],
};
const people = handleActions(
{
[getPeople.REQUEST]: state => ({
...state,
list: [],
hasLoadedPeople: false,
errorGettingPeople: false,
}),
[getPeople.FAILURE]: state => ({
...state,
errorGettingPeople: true,
}),
[getPeople.SUCCESS]: (state, { payload }) => ({
...state,
hasLoadedPeople: true,
list: payload.people,
}),
},
INITIAL_STATE,
);
export default people;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment