useReactorInfiniteQuery
useReactorInfiniteQuery is a React hook for paginated data fetching using a Reactor instance.
Import
Section titled “Import”import { useReactorInfiniteQuery } from "@ic-reactor/react"import { useReactorInfiniteQuery } from "@ic-reactor/react"import { backend } from "./reactor"
function Feed() { const { data, fetchNextPage, hasNextPage } = useReactorInfiniteQuery({ reactor: backend, // 👈 Required functionName: "list_feed", getArgs: (pageParam) => [{ cursor: pageParam, limit: 20 }] as const, initialPageParam: null as string | null, getNextPageParam: (lastPage, allPages) => lastPage.nextCursor, })
return ( <div> {data?.pages.map((page, i) => ( // Render posts <div key={i}> {page.posts.map((post) => ( <p key={post.id}>{post.title}</p> ))} </div> ))} <button onClick={() => fetchNextPage()} disabled={!hasNextPage}> Load More </button> </div> )}Options
Section titled “Options”Required Options
Section titled “Required Options”| Option | Type | Description |
|---|---|---|
reactor |
Reactor<A, T> |
The Reactor instance to use |
functionName |
string |
The canister method to call |
getArgs |
((pageParam) => Args) | skipToken |
Builds the call arguments for each page; skipToken waits for them |
initialPageParam |
TPageParam |
Page param the first fetch starts from |
getNextPageParam |
function |
Function to determine the next page param (cursor/index) |
Optional Options
Section titled “Optional Options”Same as useActorInfiniteQuery.
See Also
Section titled “See Also”- useActorInfiniteQuery — Bound version
- Reactor Hooks Overview