Open History to see the last commit
1---
2id: createQueriesController
3title: createQueriesController
4---
5β
6# Function: createQueriesController()
7β
8```ts
9function createQueriesController<TQueryOptions, TCombinedResult>(
10 host,
11 options,
12queryClient?): QueriesResultAccessor<TCombinedResult>;
13```
14β
15Defined in: [packages/lit-query/src/createQueriesController.ts:615](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createQueriesController.ts#L615)
16β
17Creates a Lit reactive controller that subscribes the host to multiple
18queries.
19β
20The returned accessor is callable and also exposes `current` and `destroy`.
21When `options` or `options.queries` is a function, it is re-read during host
22updates so the query list can follow reactive host state.
23β
24If `queryClient` is omitted, the controller resolves the client from the
25nearest connected `QueryClientProvider`.
26β
27## Type Parameters
28β
29### TQueryOptions
30β
31`TQueryOptions` *extends* `any`[]
32β
33### TCombinedResult
34β
35`TCombinedResult` = `CreateQueriesResults`\<`TQueryOptions`\>
36β
37## Parameters
38β
39### host
40β
41`ReactiveControllerHost`
42β
43The Lit reactive controller host that owns the queries
44subscription.
45β
46### options
47β
48[`Accessor`](../type-aliases/Accessor.md)\<[`CreateQueriesControllerOptions`](../type-aliases/CreateQueriesControllerOptions.md)\<`TQueryOptions`, `TCombinedResult`\>\>
49β
50Queries controller options, or a getter that returns options.
51β
52### queryClient?
53β
54`QueryClient`
55β
56Optional explicit query client. Provide this for
57controllers that should not resolve a client from Lit context.
58β
59## Returns
60β
61[`QueriesResultAccessor`](../type-aliases/QueriesResultAccessor.md)\<`TCombinedResult`\>
62β
63An accessor for the latest query results, or the value returned by
64`combine`.
65β
66## Example
67β
68```ts
69import { LitElement, html } from 'lit'
70import { createQueriesController } from '@tanstack/lit-query'
71β
72class DashboardView extends LitElement {
73 private readonly dashboard = createQueriesController(this, {
74 queries: [
75 { queryKey: ['stats'], queryFn: fetchStats },
76 { queryKey: ['projects'], queryFn: fetchProjects },
77 ],
78 combine: ([stats, projects]) => ({
79 stats: stats.data,
80 projects: projects.data ?? [],
81 isPending: stats.isPending || projects.isPending,
82 }),
83 })
84β
85 render() {
86 const dashboard = this.dashboard()
87 return html`<p>Projects: ${dashboard.projects.length}</p>`
88 }
89}
90```