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

InfiniteQueryObserver.md

24 lines662 Bytes

1---
2id: InfiniteQueryObserver
3title: InfiniteQueryObserver
4---
5​
6The `InfiniteQueryObserver` can be used to observe and switch between infinite queries.
7​
8```tsx
9const observer = new InfiniteQueryObserver(queryClient, {
10 queryKey: ['posts'],
11 queryFn: fetchPosts,
12 getNextPageParam: (lastPage, allPages) => lastPage.nextCursor,
13 getPreviousPageParam: (firstPage, allPages) => firstPage.prevCursor,
14})
15​
16const unsubscribe = observer.subscribe((result) => {
17 console.log(result)
18 unsubscribe()
19})
20```
21​
22**Options**
23​
24The options for the `InfiniteQueryObserver` are exactly the same as those of [`useInfiniteQuery`](../framework/react/reference/useInfiniteQuery).