Last active
June 25, 2019 14:07
-
-
Save DZuz14/c97a70733ab174ab398fbf6805ac0a89 to your computer and use it in GitHub Desktop.
Async Await Action Creator with Redux Thunk
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
const BACKEND_URL = 'https://fakeserver.com/api' | |
export function signUpUser(email, password) { | |
return async (dispatch) => { | |
try { | |
const signUp = await axios.post(`${BACKEND_URL}/signup`, { | |
email: email, | |
password: password | |
}) | |
// signUp.data.token <-- Access token here if the above request finished successfully. | |
dispatch({ type: 'SIGN_UP_SUCCESS' }) | |
} | |
catch(e) { | |
// catch errors here | |
dispatch({ type: 'SIGN_UP_ERROR' }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment