-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Describe the bug
I am trying to use the useQueries function to call a bunch of APIs in different regions. I expect some of them to give back 404 errors and thus I want to use the combine method to filter out only the successful methods.
However, I noticed that doing something like the following
useQueries({
queries,
combine: (results) => {
// const data = results.filter((result) => result.isSuccess).map((result) => result.data);
// console.log(results);
return {
isLoading: results.some((result) => result.isLoading),
data: results.filter((result) => result.isSuccess).map((result) => result.data)
};
},
});
where data is filtering out only the successful results causes isLoading to never settle on false and thus component stays stuck in the loading state forever.
However, if I remove the filter block, then it settles to false just fine.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/old-monad-pyr3qf
Steps to reproduce
View at the code sandbox link.
Notice how loading stays stuck on loading state.
If you remove the filter then it works fine.
Also note that you need to have atleast one API be in an error state for this bug to show up.
Expected behavior
I expect the useQueries function to settle on isLoading after all calls have finished and thus all queries in the array should be isLoading false.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: MacOS
- Browser: Arc
- Version: 5.18.1
Tanstack Query adapter
None
TanStack Query version
5.18.1
TypeScript version
4.4.4
Additional context
No response