Last active
December 2, 2018 13:08
-
-
Save smks/6e16a326a253b24c44880591a7755d53 to your computer and use it in GitHub Desktop.
Handle actions equivalent of reducer
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
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