I see that Tanstack Query supports parallel queries in a certain way that is dynamic, per this page: https://tanstack.com/query/latest/docs/framework/react/guides/parallel-queries#:~:text=each%20useSuspenseQuery%20instance.-,Dynamic%20Parallel%20Queries%20with%20useQueries,-If%20the%20number
In the example they provide, useQueries() hook is passed an array that is a prop of the component, so it is dynamic up to the point that the component is rendered and passed its props.
I have a situation where the number of parallel calls depends on the results of the previous batch of parallel calls. We are calling an endpoint that returns data paginated, but we cannot specify the page length and it does not reveal the number of pages ahead of time. The final page has in indicator that it is last. We want to make a certain number of parallel calls to this endpoint (say 10), and, if none of the responses indicates that it is the last, make another set of 10 parallel calls and so on.
I'm curious if the 'dynamic' nature of Tanstack's useQueries() is such that as the array of queries passed to it changes, the code will re-run any queries based on keys it's seen before. Taking their sample code of
queries: users.map((user) => {
return {
queryKey: ['user', user.id],
queryFn: () => fetchUserById(user.id),
}
})
If user is in component state, and that state is updated so its original value of 3 array members has 3 more appended to it, will Tanstack see that the keys of the first 3 match and not re-run those queries, but only the new ones?
I realize this is not great architecture and if we had any control over this endpoint we would be changing it and not trying to paper over its shortcomings on the front end. We need to load all the pages before the user can interact because the endpoint does not offer sorting or searching, and returns its results in an unpredictable sequence.