Chaining queries with a minimum wait time
Hi, I have a potentially weird use case and I'm hoping might be able offer some suggestions/guidance.
I have a map and a date & time picker and a react query that fetches the location etc. of a bunch of resources at that time as a feature collection and I render them on the map. The page also has a play button that when pressed sets a timeout that will advance the time fed into the query X seconds every X seconds which will then consequently update the map.
My problem is that sometime the API request takes longer than X seconds and I end up with queries getting cancelled and the map not updating.
What I thought might be a solution is to remove the timeout and instead trigger the time advance in the onSuccess callback of the query. However I know onSuccess is deprecated, plus this has the drawback of potentially completing in less than X seconds. I would like the timer to advance maximally once every X seconds.
I looked at useInfiniteQuery but it doesn't quite fit.
Apologies if this isn't the right kind of question to ask here but I'm kinda stumped, where the alternative is rolling my own solution.
Any suggestions would be greatly appreciated. Thanks!
2 Replies
fair-rose•3y ago
My suggestion: do a useEffect that updates the datetime useState if data (or dataUpdatedAt) changes. Maybe also in a timeout…
ratty-blushOP•3y ago
That helped, thanks!