Created
May 19, 2016 11:59
-
-
Save ferrannp/41ea6109bd077a1ae44c83f48fc1d767 to your computer and use it in GitHub Desktop.
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
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