Skip to content

Instantly share code, notes, and snippets.

@pedrouid
Created July 18, 2019 13:18
Show Gist options
  • Select an option

  • Save pedrouid/4cef6f9592f3ec5a8c7a9e9fef53bc72 to your computer and use it in GitHub Desktop.

Select an option

Save pedrouid/4cef6f9592f3ec5a8c7a9e9fef53bc72 to your computer and use it in GitHub Desktop.
Redux Thunk Async Example
export const accountLogin = (username: string, password: string) => async (
dispatch: any,
getState: any
) => {
dispatch({ type: ACCOUNT_LOGIN_REQUEST });
try {
const session = await apiLogin(username, password)
dispatch({ type: ACCOUNT_LOGIN_SUCCESS, payload: session });
window.browserHistory.push("/account");
} catch (error) {
dispatch(notificationShow(error.message, true));
dispatch({ type: ACCOUNT_LOGIN_FAILURE });
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment