Prevent Refetch on invalidateQueries() unless certain time has past.
My use case is I have a SignalR message that comes in that tells me when I should Refetch the page. So I call invalidateQueries each time. The problem is this can occur hundreds of times per second. By default it cancels existing queries which manifests itself by making the UI never refresh until there is no more messages for a while.
I set the cancelRefetch to false. This kind of does what I want but there is no way to set an interval.
Maybe there is a better way to do this. I basically need to disable refetchInterval when there hasn't been any SignalR messages within the last 1 second.
4 Replies
genetic-orangeOP•14mo ago
So I added a 1 second delay to the queryFn and set cancelRefetch to false. This seems to work but feels like a workaround.
absent-sapphire•14mo ago
If you invoke invalidateQueries, we expect that you want to do make a fetch now. If you don't want that, you need to delay the invocation on your end.
genetic-orangeOP•14mo ago
Yup invalidateQueries does seem like the wrong command for the job.
What I really need to do is enable refetchInterval when signalR message arrives then disable it after some amount of time without any messages arriving.
like-gold•14mo ago
It might be simpler to do that part of the logic yourself by throttling your SignalR messages