Skip to content

Instantly share code, notes, and snippets.

@vvscode
Created February 8, 2019 10:34
Show Gist options
  • Select an option

  • Save vvscode/ff778eb6a6293113da7faa3de0a12f66 to your computer and use it in GitHub Desktop.

Select an option

Save vvscode/ff778eb6a6293113da7faa3de0a12f66 to your computer and use it in GitHub Desktop.
handle-api-call-state-nicely
export function createDefaultLoadable() {
loading: false,
success: false,
error: null,
}
export function onLoadableLoad(loadable) {
return {
...loadable,
loading: true,
success: false,
error: null,
};
}
export function onLoadableSuccess(loadable) {
return {
...loadable,
loading: false,
success: true,
error: null,
};
}
export function onLoadableError(loadable, error) {
return {
...loadable,
loading: false,
success: false,
error: error,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment