错误:调度不是函数,将injectStripe和mapDispatchToProps连接起来

时间:2019-04-23 18:23:11

标签: javascript reactjs react-redux stripe-payments

我在连接mapStateToProps时遇到麻烦,因此该操作被适当地调用:

const mapDispatchToProps = (dispatch) => {
  return {
    createPayment: (token, email) => dispatch(createPaymentForToken(token, email)),
  };
};

const injectedCheckoutForm = injectStripe(CheckoutForm);
export default connect(mapDispatchToProps)(injectedCheckoutForm);

当我致电this.props.createPayment(token, email)时,出现以下错误:

  

index.js:130未捕获(承诺)TypeError:调度不是函数

编辑:我的动作似乎正在被调用,但我的传奇人物却没有听CREATE_PAYMENT动作

1 个答案:

答案 0 :(得分:2)

connect的第一个参数为mapStateToProps,第二个参数为mapDispatchToProps。而是尝试connect(null, mapDispatchToProps)

const mapDispatchToProps = (dispatch) => {
  return {
    createPayment: (token, email) => dispatch(createPaymentForToken(token, email)),
  };
};

const injectedCheckoutForm = injectStripe(CheckoutForm);
export default connect(null, mapDispatchToProps)(injectedCheckoutForm);