Created
October 22, 2016 18:56
-
-
Save zerobias/50964bc65148fd7a1b62721d2806d909 to your computer and use it in GitHub Desktop.
Redux async action creator with initial dispatching
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
function makeAjaxCall(someValue) { | |
return (dispatch, getState) => { | |
dispatch({type : "REQUEST_STARTED"}); | |
myAjaxLib.post("/someEndpoint", {data : someValue}) | |
.then(response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}) | |
.catch(error => dispatch({type : "REQUEST_FAILED", error : error}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment