How to chain queries correctly? #311
-
I'm trying to perform two queries, where the second one depends on the result of the first. For example: const { state: user } = useQuery({
key: ['user']
})
const { state: userOrders } = useQuery({
key: ['userOrders', user.data.id]
}) The problem is that user.data.id is initially undefined, so it can't be used in the second query. However, I need to wait for the second query to finish before rendering the component. |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Jun 13, 2025
Replies: 1 comment 3 replies
-
I would use data loaders with unplugin Vue router for this |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you should rethink how your queries are consumed so the
user.data.id
is always present. As you noted, this is pretty much #283 (comment). Having enabled false still requires creating an entry souserOrders
is defined. That why I believe you should rethink the way the orders query is consumed.You can ensure a query within another query with query options (typed and great when queries or keys are used in multiple places):