Skip to content

Instantly share code, notes, and snippets.

@ivawzh
Last active April 18, 2017 02:06
Show Gist options
  • Save ivawzh/96bb512e5834bf1e92857aa3b4dc5a7c to your computer and use it in GitHub Desktop.
Save ivawzh/96bb512e5834bf1e92857aa3b4dc5a7c to your computer and use it in GitHub Desktop.
Redux Login Action snippet
// @ 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