Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Last active June 25, 2019 14:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DZuz14/c97a70733ab174ab398fbf6805ac0a89 to your computer and use it in GitHub Desktop.
Save DZuz14/c97a70733ab174ab398fbf6805ac0a89 to your computer and use it in GitHub Desktop.
Async Await Action Creator with Redux Thunk
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