Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

dependent-queries.md

39 lines860 Bytes

// 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),
    })) ?? [],
}))