Dynamically update refetchTime based on query response #2068
Replies: 4 comments 5 replies
-
you can use local state for that instead of a ref. that would trigger a re-render and update your staleTime / cacheTime accordingly. I think it would be really cool to have a plugin that "translates" https headers like |
Beta Was this translation helpful? Give feedback.
-
Is there any updates on this? I have a similar use cases where I can determine Here's what I'm doing now: export function useThisQuery(queryKey, options) {
const queryClient = useQueryClient();
const cachedData = queryClient.getQueryData(queryKey);
return useQuery(
queryKey,
{
staleTime: cachedData && imSureItWontUpdate(cachedData) ? Infinity : undefined,
...options,
}
);
} |
Beta Was this translation helpful? Give feedback.
-
@SevenOutman this has always worked:
|
Beta Was this translation helpful? Give feedback.
-
I also went into this. useQuery({
queryKey: key,
queryFn: fetcher,
refetchInterval: (data) => {
if (data && data...) {
return ...
}
// default cache time
return ...
},
}) |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'd like to implement the following use case:
Would it be possible? I was also considering to update the stale or cache time, but in any case the setting applies before the query triggers.
Other solutions that I considered are:
[EDITED]
Best solution I found is
Beta Was this translation helpful? Give feedback.
All reactions