Skip to content

Instantly share code, notes, and snippets.

@Maarten88
Last active March 31, 2017 11:07
Show Gist options
  • Save Maarten88/6bd693da8b4ef0608698096de9bef9fc to your computer and use it in GitHub Desktop.
Save Maarten88/6bd693da8b4ef0608698096de9bef9fc to your computer and use it in GitHub Desktop.
async function postEffect(url: string, xsrfToken: string, data: any = {}) {
let response = await fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': xsrfToken
},
body: JSON.stringify(data)
});
return response;
}
export const actionCreators = {
increment: (): AppThunkAction<KnownAction> => async (dispatch, getState) => {
dispatch({ type: Server.INCREMENT_COUNTER });
var state = getState();
let response = await postEffect('/incrementcounter', state.session.xsrfToken);
}
// [ ... other async actions ]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment