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:398](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createInfiniteQueryController.ts#L398)
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### queryClient?
65β
66[`QueryClient`](../classes/QueryClient.md)
67β
68Optional explicit query client. Provide this for
69controllers that should not resolve a client from Lit context.
70β
71## Returns
72β
73[`InfiniteQueryResultAccessor`](../type-aliases/InfiniteQueryResultAccessor.md)\<`TData`, `TError`\>
74β
75An accessor for the latest infinite query result with page helper
76methods.
77β
78## Example
79β
80```ts
81import { LitElement, html } from 'lit'
82import { createInfiniteQueryController } from '@tanstack/lit-query'
83β
84class ProjectsView extends LitElement {
85 private readonly projects = createInfiniteQueryController(this, {
86 queryKey: ['projects'],
87 queryFn: ({ pageParam }) => fetchProjects(pageParam),
88 initialPageParam: 0,
89 getNextPageParam: (lastPage) => lastPage.nextCursor,
90 })
91β
92 render() {
93 const query = this.projects()
94β
95 return html`
96 <button ?disabled=${!query.hasNextPage} @click=${() => this.projects.fetchNextPage()}>
97 Load more
98 </button>
99 `
100 }
101}
102```