如何在this.props中使用“ .then()”

时间:2020-03-18 13:03:52

标签: javascript reactjs react-redux

当我们单击显示API更新表单的按钮时,我具有处理提交功能。在此期间,将显示API加载程序的等待时间。但是当我尝试此代码时出现错误

TypeError:“ _ this.props.setDeviceInfoAction(...)。然后”不是函数

这是Handlesubmit函数:

handleSubmit = (e) => {
   e.preventDefault();
   this.props.form.validateFieldsAndScroll((err, values) => {
     if (!err) {
       this.props.setDevicEtherConfigAction(values).then(() => {
         this.props.showLoaderAction();
       });
     }
   });
}

//********************* Action**************************//
export const setDeviceInfoAction = (values) => {
  return {
    type: SET_DEVICE_INFO,
    payload: {
      values
    }
  };
};

//********************* Sagas**************************//
function* setDeviceInfo({ payload }) {
  try {
    const data = yield call(setDeviceInfoRequest, payload.values);
    if (data === 200) {
      yield put(showAlertAction(...........................));
    } else {
      yield put(showAlertAction(...........................));
    }
  } catch (error) {}
}

export function* setDeviceInfoFork() {
  yield takeEvery(SET_DEVICE_INFO, setDeviceInfo);
}

//***********************Service*******************************//
export const setDeviceInfoRequest = async (payload) => {
  let request = ..........................
  var AuthToken = .........................
  return new Promise(function (resolve, reject) {
    client........(request, {'x-authorization': AuthToken}, (err, response) => {
      var status = 200
      if (response === null) {
        resolve(false);
      } else {
        resolve(status);
      }
    });
  })
}

0 个答案:

没有答案