Skip to content

Instantly share code, notes, and snippets.

@marcoleong
Last active March 10, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoleong/547636508c6778c9cfc7054c403ba86b to your computer and use it in GitHub Desktop.
Save marcoleong/547636508c6778c9cfc7054c403ba86b to your computer and use it in GitHub Desktop.
function receiveLoginUser (user) {
return {type: 'RECEIVE_LOGIN_USER', payload: user}
}
function login (email, password) {
return (dispatch) => {
// 可以呢到再dispatch(loadingLogin(true))
return axios.post("xxxx/login", { email, password }).then(response => {
dispatch(receiveLoginUser(response.user))
})
}
}
export { login }
// react
import { login } from './login.js'
//.....omitted
const mapDispatchToProps = (dispatch) => {
return {
login: (email, password) => {
dispatch(login(email, password))
}
}
}
connect(null, mapDispatchToProps)(SomeComponent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment