反应本机函数不触发



所以,我有这个组件,

{ this.props.isConfirmModalOpen && shiftInvite && <ConfirmApplicationPopUp
  memberPhoto={props.memberProfile && props.memberProfile.photo}
  venueLogo={getOr('noop', 'account.logo', shiftInvite)}
  isOpen={props.isConfirmModalOpen}
  shift={shiftInvite}
  isOnboarding={isOnboardingMember}
  onClose={props.onToggleConfirmPopUp}
  onConfirm={this.handleConfirmApplication}
  checkValues={props.confirmationCheckValues}
  onUpdateCheckValues={props.onUpdateConfirmationCheckValues}
  isHomeComponent
/> }

您可以看到,我通过conconfirm on handleconfirmapplication函数,这是对某些内容的检查,必须在try块中运行一个函数,这是函数

handleConfirmApplication = async () => {
    const checkVals =
      get('shift.account.accountName', this.props) === ONBOARDING_ACCOUNT
        ? omit('payRate', this.props.confirmationCheckValues)
        : this.props.confirmationCheckValues;
    if (Object.values(checkVals).every(val => val)) {
      this.props.onToggleConfirmPopUp();
      this.props.onToggleLoadingApply();
      try {
        console.log('inTry1');
        await this.handleShiftInviteDecision('ACCEPT');
        console.log('inTry2');
      } catch (e) {
        Alert.alert('Error', parseError(e));
      } finally {
        this.props.onToggleLoadingApply();
        console.log('inFinally');
      }
    } else {
      Alert.alert('Error', 'Please confirm all shift requirements');
    }
  };

我的问题是,无论出于何种原因,它都不会运行handleshiftinvitedecision('接受),无论如何,我正在等待它,试图将其放入另一个功能,从另一个功能等不运行!这是handleshiftinvitedEcision函数

  handleShiftInviteDecision = (decision: 'ACCEPT' | 'DECLINE') => async () => {
    console.log('handleSIDecision1');
    const [shiftInvite] = getOr([], 'shiftInvites', this.state.modals);
    console.log('handleSIDecision2');
    if (decision === 'ACCEPT') {
      analytics.hit(new PageHit(`ShiftInviteModal-ACCEPT-${shiftInvite.id}`));
      console.log('handleSIDecision3');
    } else if (decision === 'DECLINE') {
      analytics.hit(new PageHit(`ShiftInviteModal-DECLINE-${shiftInvite.id}`));
      console.log('handleSIDecision4');
    }
    try {
      console.log("thisSHouldRun")
      this.setState({ isLoading: true, display: false });
      await this.props.updateMyApplication(shiftInvite.id, decision);
      console.log('handleSIDecision5');
    } catch (e) {
      Alert.alert('Error', parseError(e));
    } finally {
      this.setState({ isLoading: false, display: false });
    }
  };

我能做的任何意识到吗?

函数 handleShiftInviteDecision是返回 async函数的函数。

handleShiftInviteDecision = (decision: 'ACCEPT' | 'DECLINE') => async () => {

因此,您需要调用async功能,它返回以调用它:

  try {
    console.log('inTry1');
    await this.handleShiftInviteDecision('ACCEPT')();  // <--- here
    console.log('inTry2');
  } catch (e) {

相关内容

最新更新