T
TanStack2y ago
other-emerald

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),
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();
}
},
onPaginationChange: async (updater) => {
if (typeof updater === 'function') {
setPagination(updater({ pageIndex, pageSize }));
// Ideally I'd have a conditional guarding this next call
await nextPage();
}
},
1 Reply
exotic-emerald
exotic-emerald2y ago
You can read the current pageIndex in the table.getState().pagination.pageIndex and compare it with the new value. Or I didn't understand the question correctly?

Did you find this page helpful?