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