Open History to see the last commit
1---
2id: dependent-queries
3title: Dependent Queries
4ref: docs/framework/react/guides/dependent-queries.md
5replace: { 'useQuery': 'injectQuery', 'useQueries': 'injectQueries' }
6---
7β
8[//]: # 'Example'
9β
10```ts
11// Get the user
12userQuery = injectQuery(() => ({
13 queryKey: ['user', email],
14 queryFn: getUserByEmail,
15}))
16β
17// Then get the user's projects
18projectsQuery = injectQuery(() => ({
19 queryKey: ['projects', this.userQuery.data()?.id],
20 queryFn: getProjectsByUser,
21 // The query will not execute until the user id exists
22 enabled: !!this.userQuery.data()?.id,
23}))
24```
25β
26[//]: # 'Example'
27[//]: # 'Example2'
28β
29```ts
30projectsQueries = injectQueries(() => ({
31 queries:
32 this.userQuery.data()?.projectIds.map((projectId) => ({
33 queryKey: ['project', projectId],
34 queryFn: () => getProjectById(projectId),
35 })) ?? [],
36}))
37```
38β
39[//]: # 'Example2'