Skip to content

Commit e03cc3a

Browse files
authored
docs(query): update the documentation of dependent queries in Vue section (TanStack#7243)
The documentation is confusing and not clear about how to use dependent queries in Vue. This PR updates the documentation to make it clear and easy to understand. discussion: TanStack#7220
1 parent 7487ce0 commit e03cc3a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/framework/vue/guides/dependent-queries.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,31 @@ const { isIdle, data: projects } = useQuery({
2525
```
2626
2727
[//]: # 'Example'
28+
[//]: # 'Example2'
29+
30+
```tsx
31+
// Get the users ids
32+
const { data: userIds } = useQuery({
33+
queryKey: ['users'],
34+
queryFn: getUsersData,
35+
select: (users) => users.map((user) => user.id),
36+
})
37+
38+
const queries = computed(() => {
39+
return userIds.value.length
40+
? userIds.value.map((id) => {
41+
return {
42+
queryKey: ['messages', id],
43+
queryFn: () => getMessagesByUsers(id),
44+
}
45+
})
46+
: []
47+
})
48+
49+
// Then get the users messages
50+
const usersMessages = useQueries({
51+
queries, // if users is undefined, an empty array will be returned
52+
})
53+
```
54+
55+
[//]: # 'Example2'

0 commit comments

Comments
 (0)