TanStackT
TanStack2y ago
5 replies
popular-magenta

Wait invalidate infinite query

const handleDeclineLeadOffer = async () => {
    if (!declineOfferReason) return showToast('Escolha uma opção de declínio');

    if (shouldOnlyDeclineMeeting) {
      await meetingAction({
        action: MeetingActionEnum.DECLINED,
        leadType,
        meetingId: lead?.meeting?.id as string,
        declinedReason: declineOfferReason,
      });

      return;
    }

    await updateLead({
      type: leadType,
      leadId: leadId || (lead?.id as string),
      status: LeadMundoInvestStatusEnum.FINALIZADO,
      declinedReason: declineOfferReason,
    });

    await queryClient.invalidateQueries(modalOptions?.invalidateQueriesKey);

    goBack();

    return showToast('Declínio realizado com sucesso!');
  };


I have this function, I would like to await the invalidation because when I go back, I need to refetch all pages again and the card I "removed" takes some time to disappear, causing some bad user experience, there is a way to invalidate and wait all pages to be refetch before going back?
Was this page helpful?