Skip to content

Instantly share code, notes, and snippets.

@emilong
Last active April 7, 2016 16:37
Show Gist options
  • Save emilong/5e8fe5925912fa12dfe3dd35686ae383 to your computer and use it in GitHub Desktop.
Save emilong/5e8fe5925912fa12dfe3dd35686ae383 to your computer and use it in GitHub Desktop.
function fetchSomething(thingId) {
return (dispatch) => {
// update call metadata
dispatch(startRequest(thingId))
return fetch(`https://api.example.com/things/${thingId}`)
.then((response) => response.json())
// send the result of the call, probably updating the request metadata as well
.then((json) => dispatch(receiveAThing(json)))
// update the metadata to indicate a failure
.catch((err) => dispatch(thingGettingFailed(err)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment