Best way to combine loading status of multiple queries? #2951
-
I have a loading page which I want to display while I wait for 2 query to complete. I have both of these queries in their own custom hooks. So far I'm doing something like this:
The custom hook looks like this:
This works but it feels a bit clunky so I was wondering if there was a more elegant way? I was looking at using useQueries but that requires multiple queries to be passed in, which would be awkward for me to do as I have all of my queries in custom hooks. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't think there is a general solution, as it highly depends on the use case. With concurrently running queries, it is sometimes correct to wait for all of the queries to succeed before showing data (like in your example), but sometimes, it is also correct to show any data as soon as you have it, and only show the big loading spinner while all queries are loading. This is conceptually the same when using combining the requests in one fetching function with |
Beta Was this translation helpful? Give feedback.
I don't think there is a general solution, as it highly depends on the use case. With concurrently running queries, it is sometimes correct to wait for all of the queries to succeed before showing data (like in your example), but sometimes, it is also correct to show any data as soon as you have it, and only show the big loading spinner while all queries are loading. This is conceptually the same when using
useQueries
or separateuseQuery
calls.combining the requests in one fetching function with
Promise.all
can also work but of course has other drawbacks, like coupling them together into one query.