refetchInterval triggered multiple times. #7823
-
Hi, below is my code using the const query = useQuery({
retry: false,
gcTime: 1000,
queryKey: [QUERY_KEY, transferId],
staleTime: 0,
queryFn: async () => {
console.log('fetch query');
const response = await transerApi.getTransfer(transferId);
return response;
},
refetchInterval: ({ state }) => {
const { dataUpdateCount } = state;
console.log('fetch interval');
if (dataUpdateCount > 10) {
return false;
}
return 200;
},
}); I have 2 console.log. One is inside the queryFn and another one is at refetchInterval. I notice that the console.log inside the refetchInterval get called first. Not only that it was called multiple times before the console.log inside the queryFn get executed. I am trying to understand what is going on here. Can anyone clarify this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
we call the function a lot internally to calculate the interval. Timers need to be re-calculated every time options update / new data comes in etc. This can happen on every render. It's a pure function so it shouldn't matter to you how often we call it. |
Beta Was this translation helpful? Give feedback.
we call the function a lot internally to calculate the interval. Timers need to be re-calculated every time options update / new data comes in etc. This can happen on every render. It's a pure function so it shouldn't matter to you how often we call it.