Loading state for dependent queries recipe #1569
Replies: 1 comment 1 reply
-
with custom hooks, I like to keep the interface that they expose identical or close to the standard react-query syntax, so that we have least-surprise with using them. So I would just "override" the returned isLoading and
of course - what about the Also note that the second query will be in
this might even be easier for this case, because you can just return the second query as-is. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Following the recipe for dependent queries from the docs, is there an idiomatic way to get the loading state of the final query?
For example, if there is a fast query that depends on a slow query, how can we show a spinner while the two are loading?
Scenario
Given this hook
And a component that uses it:
We'll only see the spinner while the fast query is in a loading state.
Current approach
We have a pattern of forwarding the dependent query results to the caller in an array:
Consumers can then apply "status predicates" to find out if a list of queries is loading.
This pattern is verbose and leaky (callers can depend the list of dependent queries in weird ways), but it does solve the problem.
Is there a better way to go about this?
Beta Was this translation helpful? Give feedback.
All reactions