Skip to content

Instantly share code, notes, and snippets.

@vvscode
Created February 8, 2019 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvscode/693f36f8729b9833cc019c7114166342 to your computer and use it in GitHub Desktop.
Save vvscode/693f36f8729b9833cc019c7114166342 to your computer and use it in GitHub Desktop.
handle-api-call-state-nicely
export function withLoadable(baseReducer, {loadingActionType, successActionType, errorActionType}) {
return (state, action) => {
if (action.type === loadingActionType) {
state = onLoadableLoad(state);
}
if (action.type === successActionType) {
state = onLoadableSuccess(state);
}
if (action.type === errorActionType) {
state = onLoadableError(state, action.error);
}
return baseReducer(state, action);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment