InfiniteQueryObserver
#
The InfiniteQueryObserver
can be used to observe and switch between infinite queries.
1const observer = new InfiniteQueryObserver(queryClient, {
2 queryKey: ['posts'],
3 queryFn: fetchPosts,
4 getNextPageParam: (lastPage, allPages) => lastPage.nextCursor,
5 getPreviousPageParam: (firstPage, allPages) => firstPage.prevCursor,
6})
7
8const unsubscribe = observer.subscribe((result) => {
9 console.log(result)
10 unsubscribe()
11})
Options
The options for the InfiniteQueryObserver
are exactly the same as those of useInfiniteQuery
.