Skip to content

Instantly share code, notes, and snippets.

View MisterPea's full-sized avatar
:octocat:
Occasionally epistemically ambivalent

Perry Angelora MisterPea

:octocat:
Occasionally epistemically ambivalent
View GitHub Profile
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);