Skip to content

Instantly share code, notes, and snippets.

@baranovxyz
Last active May 3, 2020 21:21
Show Gist options
  • Save baranovxyz/755b875ce0e15240012c17fed5e6f15c to your computer and use it in GitHub Desktop.
Save baranovxyz/755b875ce0e15240012c17fed5e6f15c to your computer and use it in GitHub Desktop.
function updateState(dispatch) {
dispatch(SET_STATUS({ status: 'submitting' }));
return fetch('https://example.com/api/a')
.then(() => {
dispatch(SET_STATUS({ status: 'processing' }));
return fetch('https://example.com/api/b')
.then(response => {
return response
.json()
.then(data => {
dispatch(SET_STATE({ data }));
})
.catch(e => {
dispatch(SET_STATUS({ status: 'error', message: e.message }));
});
})
.catch(e => {
dispatch(SET_STATUS({ status: 'error', message: e.message }));
});
})
.catch(e => {
dispatch(SET_STATUS({ status: 'error', message: e.message }));
})
.finally(() => {
dispatch(SET_STATUS({ status: 'finished' }));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment