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