Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

createInfiniteQueryController.md

111 lines3.0 KB

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 }
111```