繁体   English   中英

使用 redux-thunk 调用异步操作创建器助手

[英]Invoking an async action creator helper with redux-thunk

我正在尝试为两个异步操作创建者调用辅助方法,但我不确定为什么我不能这样做。 分配给signUpOrSignIn应该由signUpsignIn调用。 这些都在同一个文件中。 我认为这个问题涉及我的 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);
};

由于signUpsignIn打算只返回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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM