TanStackT
TanStack2y ago
4 replies
significant-gray

I have some question regarding pagination

Hello we are doing a fullstack project and we have a fetch query

const LIMIT = 7

export const getHoldings = async ({pageParam}: {pageParam: number}) => {
    return (
        await AxiosInstance.get(`/asset/user?page=${pageParam}&limit=${LIMIT}`)
    ).data
}

// this on the hook
export const useEmployeesWithHoldings = () => {
    return useInfiniteQuery({
        initialPageParam: 1,
        queryKey: ['usersWithHoldings'],
        queryFn: ({ pageParam = 1 }) => getHoldings({ pageParam }),
        getNextPageParam: (lastPage, allPages) => {
            return lastPage.totalPages > allPages.length ? allPages.length + 1 : undefined;
        },
    });

}

Now the data I get from the backend is this
{
data: []
totalPages: number,
all: number (all documents)
}


So how would I fetch and map how to get the total pages to limit it
Was this page helpful?