[英]redux-thunk: Pause Component Execution Until Action Creator Completes
[英]Invoking an async action creator helper with redux-thunk
我正在尝试为两个异步操作创建者调用辅助方法,但我不确定为什么我不能这样做。 分配给signUpOrSignIn
应该由signUp
和signIn
调用。 这些都在同一个文件中。 我认为这个问题涉及我的 function 声明或处理async dispatch
。 非常感谢您的反馈。 谢谢!
import axios from "axios";
import * as types from "./types";
const signUpOrSignIn = (path, email, password, history) => async dispatch => {
try {
const res = await axios.post(path, { email, password });
history.push("/dashboard");
dispatch({ type: types.DID_SIGN_IN, payload: res });
} catch (err) {
dispatch({ type: types.DID_SIGN_IN, payload: err.response });
}
};
export const signUp = (email, password, history) => async dispatch => {
signUpOrSignIn("/users", email, password, history);
};
export const signIn = (email, password, history) => async dispatch => {
signUpOrSignIn("/users/login", email, password, history);
};
由于signUp
或signIn
打算只返回signUpOrSignIn
。
您可以删除async dispatch
。
像这样:
export const signUp = (email, password, history) => signUpOrSignIn("/users", email, password, history);
export const signIn = (email, password, history) => signUpOrSignIn("/users/login", email, password, history);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.