Skip to content

Instantly share code, notes, and snippets.

@mvbattan
Last active December 14, 2017 13:07
Show Gist options
  • Save mvbattan/7123a901c8e7b635c4a874fe1593afda to your computer and use it in GitHub Desktop.
Save mvbattan/7123a901c8e7b635c4a874fe1593afda to your computer and use it in GitHub Desktop.
Async with behavior
const actionCreators = {
fetchSomething: () => async dispatch => {
dispatch({ type: actions.FETCH });
const response = Service.fetch();
if (response.ok) {
dispatch({ type: actions.FETCH_SUCCESS, payload: response.data });
dispatch(navigationActions.push('/successRoute');
} else {
dispatch({ type: actions.FETCH_ERROR, payload: response.error });
if (response.status === 404) {
dispatch(navigationActions.push('/failureRoute');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment