TanStackT
TanStack3y ago
1 reply
skinny-azure

How to determine pagination direction

I'm trying to do manual pagination over a collection returned from Apollo GQL using Relay-style pagination.

I'm trying to figure out how to determine if nextPage() or previousPage() was called so I know whether or not to call the fetchMore function. When users page backwards, I simply offset the data accordingly
  const table = useReactTable({
    data: data.slice(pageIndex * 10, pageIndex * 10 + 10),


but currently I can't avoid calling fetchMore on any pagination action because I have no way to know if I went backwards or forwards.

    onPaginationChange: async (updater) => {
      if (typeof updater === 'function') {
        setPagination(updater({ pageIndex, pageSize }));
        // Ideally I'd have a conditional guarding this next call
        await nextPage();
      }
    },
Was this page helpful?