Created
February 8, 2019 10:34
-
-
Save vvscode/ff778eb6a6293113da7faa3de0a12f66 to your computer and use it in GitHub Desktop.
handle-api-call-state-nicely
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
| 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