Choosing Between Offset‑Based and Cursor‑Based Pagination in RTK Query
26K reputation · 02 Nov 2021, 01:10 UTC
Determine whether offset‑based or cursor‑based pagination should be the default approach when using RTK Query’s useGetPostsQuery hook for large datasets that experience frequent inserts, deletions, or reordering.
Offset‑based pagination relies on changing limit and offset arguments, which RTK Query treats as part of the query key and automatically refetches when they change. However, if the underlying collection mutates between requests, the same offset can return duplicate or skipped items, a behavior RTK Query does not mitigate automatically.
Cursor‑based pagination avoids this instability by returning opaque tokens from the server, but the RTK Query documentation does not prescribe a preferred strategy nor provide built‑in helpers for cursor handling, leaving the decision to the developer.
What factors should guide the choice between offset‑based and cursor‑based pagination in RTK Query? How can developers mitigate duplicate or skipped items when using offset‑based pagination?