TanStackT
TanStack12mo ago
4 replies
spotty-amber

Tracking ongoing refetch attempts in useQueries' refetchInterval

Hey everyone!

I have a function inside useQueries's refetchInterval that refetches a query up to three times based on certain conditions.

return useQueries({
  queries: assetIds.map((assetId) => ({
    queryKey: inspectionQueryKey.photoStatus(assetId),
    queryFn: () => getPhotoUploadStatus<Api.AssetUploadStatus>({ queryParams: `/${assetId}/status` }),
    retry: PHOTO_UPLOAD_RETRY_COUNT,
    retryDelay: (attempt: number) => attempt * 1000,
    refetchInterval: ({ state }: Query<Api.AssetUploadStatus>) =>
      state.dataUpdateCount <= PHOTO_UPLOAD_RETRY_COUNT && !state.data?.processed
        ? 1000 * state.dataUpdateCount
        : false,
    staleTime: Infinity,
    enabled: photoInfoMutationStatus === "success" && photoUploadMutationStatus === "success" && !!assetId,
  })),
});


Until all the refetch attempts are done, I need to keep showing a spinner.

From what I’ve checked, when refetchInterval runs, isFetching is
true
, and if it succeeds, isSuccess is also
true
. But between refetch attempts, the query goes into an idle state, so I can’t rely on any flag to track ongoing attempts.

Is there a way to detect if the query still has remaining refetchInterval attempts so I can use that to show the spinner?

Thanks in advance!
Was this page helpful?