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