Skip to content

Instantly share code, notes, and snippets.

@ferrannp
Created May 19, 2016 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferrannp/41ea6109bd077a1ae44c83f48fc1d767 to your computer and use it in GitHub Desktop.
Save ferrannp/41ea6109bd077a1ae44c83f48fc1d767 to your computer and use it in GitHub Desktop.
import 'whatwg-fetch';
...
export function fetchData(id) {
return (dispatch, getState) => {
if(getState().id === id)) {
return; // No need to fetch
}
dispatch(requestData(id));
return fetch('/api/data/' + id)
.then(checkResponse)
.then(response => response.json())
.then(json => dispatch(receiveDataSuccess(json)))
.catch(error => dispatch(receiveDataFailure(error)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment