T
TanStack2y ago
stormy-gold

Refresh Infinite Query on Interval

We are using useInfiniteQuery but want to fetch the previous page every 5 seconds. So we've created a custom hook that calls useInfiniteQuery and then has a useEffect that sets up an interval. However, when there are multiple components calling the hook, we only want one interval between them. Is there a way to check how many subscribers a hook has (which we can use to set up an interval on the first subscriber)?
3 Replies
sensitive-blue
sensitive-blue2y ago
I do not understand the use case. What’s wrong with refetchInterval?
stormy-gold
stormy-goldOP2y ago
I don't want to refresh the current data, I want to fetch the previous page on an interval. Can that be done with refresh interval?
sensitive-blue
sensitive-blue2y ago
No. I think useEffect is fine for you 🙂 And regarding your other questions: that is why onSuccess was removed.

Did you find this page helpful?