Created
July 18, 2019 13:18
-
-
Save pedrouid/4cef6f9592f3ec5a8c7a9e9fef53bc72 to your computer and use it in GitHub Desktop.
Redux Thunk Async Example
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
| 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