Last active
April 18, 2017 02:06
-
-
Save ivawzh/96bb512e5834bf1e92857aa3b4dc5a7c to your computer and use it in GitHub Desktop.
Redux Login Action snippet
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
// @ redux/actions/login.js | |
export function loginStart(username, pw): Promise<void> { | |
return async (dispatch) => { | |
dispatch({ type: 'LOGIN_START' }) | |
try { | |
const userData = await login(username, pw) | |
dispatch(loginSuccess(userData)) | |
} catch (error) { | |
dispatch(loginFailure(error)) | |
} | |
} | |
} | |
export function loginSuccess(userData): Action { | |
return { type: 'LOGIN_SUCCESS', userData } | |
} | |
export function loginFailure(error): Action { | |
return { type: 'LOGIN_FAILURE', error } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment