【问题标题】:How to use async functions in react redux如何在 react redux 中使用异步函数
【发布时间】:2018-09-29 19:06:43
【问题描述】:

我在这里使用 Redux 和 React.js 我的 handleSubmit 方法:

 handleSubmit = async (e) => {
    e.preventDefault();
    await this.props.createCoupon({
        value: this.state.value,
        expiresDate: new Date(this.state.expiresDate)
    });
    this.props.fetchCoupons();
}

从逻辑上讲,fetchCoupons 函数将在 createCoupon 完成后运行,这可行,但我在 CREATE_COUPON_SUCCESS 之前和之后进入我的控制台 FETCH_COUPONS_REQUEST,这是怎么回事?

【问题讨论】:

    标签: javascript reactjs asynchronous redux


    【解决方案1】:

    试试这样的

    handleSubmit = async (e) => {
    e.preventDefault();
    await this.props.createCoupon();
    this.props.fetchCoupons();
     },
    
     createCoupon(){
         value: this.state.value,
         expiresDate: new Date(this.state.expiresDate)
        }
    

    【讨论】:

      猜你喜欢
      • 2022-07-19
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多