With keepPreviousData
refetch is triggered for previously cached key
#1996
-
Hello, folks! I'm struggling to understand why is this possible, so: I have a query with Unfortunately, I see a re-fetch every time I'm switching from a key to another, even if the data was previously loaded and within the timeframe of 2 minutes. Key example: I'm almost sure I'm missing something. What could be the reason for triggering a re-fetch if the keys are the same but the time to re-fetch has not passed yet? 🤔 Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
if you change the queryKey, react-query will refetch stale queries. what would prevent a request here is setting an appropriate |
Beta Was this translation helpful? Give feedback.
if you change the queryKey, react-query will refetch stale queries.
refetchInterval
does not prevent that, because that is a per-query-key setting, and you are switching the key.keepPreviousData
also does not prevent it, because it just tells react-query to keep showing the old data until you have the new data when switching keys instead of showing a loading spinner. Kind of what suspense for data fetching is going to provide naturally. But it does not prevent a request.what would prevent a request here is setting an appropriate
staleTime
. this time tells react-query for how long a query is to be consideredfresh
, and while data isfresh
, you will always get it from the cache, without b…