簡體   English   中英

React Native函數未觸發

[英]React Native function not triggering

所以,我有這個組成部分,

{ 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
/> }

如您所見,我繼續傳遞onConfirm 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('ACCEPT),我正在等待,嘗試將其放在另一個函數中,並從另一個函數ETC中調用它們,該函數無法運行! 這也是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) {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM