Open History to see the last commit
1---
2id: createInfiniteQueryController
3title: createInfiniteQueryController
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function createInfiniteQueryController<TQueryFnData = unknown, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(
10 host: ReactiveControllerHost,
11 options: Accessor<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>,
12 queryClient?: QueryClient
13): InfiniteQueryResultAccessor<TData, TError>;
14```
15β
16Defined in: [packages/lit-query/src/createInfiniteQueryController.ts:401](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createInfiniteQueryController.ts#L401)
17β
18Creates a Lit reactive controller that subscribes the host to an infinite
19query.
20β
21The returned accessor is callable and also exposes `current`, `refetch`,
22`fetchNextPage`, `fetchPreviousPage`, and `destroy`. When `options` is a
23function, it is re-read during host updates so query keys and options can
24follow reactive host state.
25β
26If `queryClient` is omitted, the controller resolves the client from the
27nearest connected `QueryClientProvider`.
28β
29## Type Parameters
30β
31### TQueryFnData
32β
33`TQueryFnData` = `unknown`
34β
35### TError
36β
37`TError` = `Error`
38β
39### TData
40β
41`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
42β
43### TQueryKey
44β
45`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
46β
47### TPageParam
48β
49`TPageParam` = `unknown`
50β
51## Parameters
52β
53### host
54β
55`ReactiveControllerHost`
56β
57The Lit reactive controller host that owns the infinite query
58subscription.
59β
60### options
61β
62[`Accessor`](../type-aliases/Accessor.md)\<[`CreateInfiniteQueryOptions`](../type-aliases/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\>
63β
64Infinite query observer options, or a getter that returns
65options.
66β
67<a id="options-properties"></a>
68β
69#### `options` properties
70β
71Built from [`InfiniteQueryObserverOptions`](../interfaces/InfiniteQueryObserverOptions.md#properties). See the type above for what it changes.
72β
73### queryClient?
74β
75[`QueryClient`](../classes/QueryClient.md)
76β
77Optional explicit query client. Provide this for
78controllers that should not resolve a client from Lit context.
79β
80## Returns
81β
82[`InfiniteQueryResultAccessor`](../type-aliases/InfiniteQueryResultAccessor.md)\<`TData`, `TError`\>
83β
84An accessor for the latest infinite query result with page helper
85methods.
86β
87## Example
88β
89```ts
90import { LitElement, html } from 'lit'
91import { createInfiniteQueryController } from '@tanstack/lit-query'
92β
93class ProjectsView extends LitElement {
94 private readonly projects = createInfiniteQueryController(this, {
95 queryKey: ['projects'],
96 queryFn: ({ pageParam }) => fetchProjects(pageParam),
97 initialPageParam: 0,
98 getNextPageParam: (lastPage) => lastPage.nextCursor,
99 })
100β
101 render() {
102 const query = this.projects()
103β
104 return html`
105 <button ?disabled=${!query.hasNextPage} @click=${() => this.projects.fetchNextPage()}>
106 Load more
107 </button>
108 `
109 }
110}
111```