From ec8eb14442c4241ce30353ac9cd3210936ce8083 Mon Sep 17 00:00:00 2001 From: Christian Baroni <7061887+christianbaroni@users.noreply.github.com> Date: Sat, 4 Jan 2025 02:22:10 +0000 Subject: [PATCH] Add `disableAutoRefetching` --- src/state/internal/createQueryStore.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/state/internal/createQueryStore.ts b/src/state/internal/createQueryStore.ts index 91032e9208a..9e48d80d7e0 100644 --- a/src/state/internal/createQueryStore.ts +++ b/src/state/internal/createQueryStore.ts @@ -238,6 +238,13 @@ export type QueryStoreConfig { + if (disableAutoRefetching) return; const effectiveStaleTime = options?.staleTime ?? staleTime; if (effectiveStaleTime <= 0 || effectiveStaleTime === Infinity) return; + if (activeRefetchTimeout) { clearTimeout(activeRefetchTimeout); activeRefetchTimeout = null; @@ -824,7 +834,7 @@ export function createQueryStore< set(state => ({ ...state, queryKey: currentQueryKey })); - if (subscriptionCount === 1 && enabled) { + if ((subscriptionCount === 1 || disableAutoRefetching) && enabled) { if (isStale() || !get().queryCache[currentQueryKey]?.lastFetchedAt) { fetch(currentParams); } else {