Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created October 22, 2016 18:56
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 zerobias/50964bc65148fd7a1b62721d2806d909 to your computer and use it in GitHub Desktop.
Save zerobias/50964bc65148fd7a1b62721d2806d909 to your computer and use it in GitHub Desktop.
Redux async action creator with initial dispatching
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