Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 860 Bytes

File metadata and controls

39 lines (33 loc) · 860 Bytes
id dependent-queries
title Dependent Queries
ref docs/framework/react/guides/dependent-queries.md
replace
useQuery useQueries
injectQuery
injectQueries
// Get the user
userQuery = injectQuery(() => ({
  queryKey: ['user', email],
  queryFn: getUserByEmail,
}))

// Then get the user's projects
projectsQuery = injectQuery(() => ({
  queryKey: ['projects', this.userQuery.data()?.id],
  queryFn: getProjectsByUser,
  // The query will not execute until the user id exists
  enabled: !!this.userQuery.data()?.id,
}))
projectsQueries = injectQueries(() => ({
  queries:
    this.userQuery.data()?.projectIds.map((projectId) => ({
      queryKey: ['project', projectId],
      queryFn: () => getProjectById(projectId),
    })) ?? [],
}))