T
TanStack3y ago
harsh-harlequin

useQuery only fetch if cache empty

Is there a built in setting to only run the fetch in a useQuery if the cache is empty? I can think of a way to do it with queryClient.getQueryData and using that value to set the enabled property of a subsequent useQuery. But that seems redundant. staleTime: Infinity doesnt seem to work. Because it only applies to a single useQuery right? So if another component had retrieved the same data, I want this new component to not make the fetch because its already in the cache.
2 Replies
passive-yellow
passive-yellow3y ago
staleTime infinity does this
harsh-harlequin
harsh-harlequinOP3y ago
ok thanks! maybe my testing was just messed up by something, will try again

Did you find this page helpful?