Replies: 2 comments 9 replies
-
Just for reference: there is no why would we need the tuple syntax (with a name) if we could just do:
where each entry would get, as an input, the result of the queryFn of the previous query. Of course, if you need access to the |
Beta Was this translation helpful? Give feedback.
-
Hey, @Newbie012 sorry for breaking in, but is the problem with "Move the dependent query to a child"? Looks like you will have better application in a such way? Moreover, React team recommends to split your components as much as you can) So, what is a cost of this idea? |
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.
-
The issue
When we have dependent queries inside the same component, we have a few ways to tackle it:
enabled
based on the previous query with type assertions or code validation (since TypeScript can't know based on theenabled
property if the previous query data is ready or not:All of these approaches come with a cost. Either it impacts your DX or your UX.
The proposal -
useSequentialQueries
A custom hook that invokes queries in a sequential way (one after another) while granting each query access to the previous queries.
For instance:
I'll break down what's going on here:
useSequentialQueries
with a dynamic amount of arguments.Edge cases
Beta Was this translation helpful? Give feedback.
All reactions