Stop refetchInterval after 5 call
Hi I’m wondering if there is a way to stop refetchInterval after the fifth call?
3 Replies
extended-salmon•4y ago
refetchInterval can be a function, which gets passed the current data and the query, this can be used to return true/false depending on the last response.
The query contains query.state.dataUpdateCount so yes, you can check for that numberabsent-sapphireOP•4y ago
I also checked that but when the queryKey state change to inactive then turn back to stale, the state.dataUpdateCount is still kept because of the cache I believe. I can of course disable the cache so I don’t have that issue but I want to keep it.
But I was able to solved by doing some setTimeout.
Thank you for your help/suggestions
extended-salmon•4y ago
Well you said "after 5 calls", not: "after 5 calls each time I mount a new query instance"...
You can always create a ref and keep track of the count per component