Skip to content
Discussion options

You must be logged in to vote

I figured it out and switched up the getNextPageParam in the query hook.

// useInfiniteScroll hook
export function useInfiniteScroll(query: any, pageSize: number) {
    return useInfiniteQuery({
        queryKey: ['all-items', query, pageSize],
        queryFn: ({ pageParam = null }) => getItems(query, pageParam, pageSize),

        getNextPageParam: (lastPage, allPages) => {
            // lastPage.length returns fetched page size
            // if last page length is less than pageSize then we know there won't be another page if fetched
            
            const nextPage: number | undefined = lastPage.length === pageSize ? allPages.length : undefined;
            return nextPage;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jinsley8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant