url-pagination
This project has 2 goals:
- provide utilities to compute pagination params inside your React components
- persist pagination params as a part of URL so a page can be reloaded and linked to (currently we support Next.js router).
Getting started
In your shell:
In your component:
If you want to keep pagination in React state instead of URL, instead of useUrlPagination
use usePagination
.
useUrlPagination
useUrlPagination(args: UseUrlPaginationArgs): PageInfo
has the following signature:
usePagination
usePagination(args: UsePaginationArgs): PageInfo
has the following signature (PageInfo
is the same as for UseUrlPaginationArgs
):
calculatePage
Utility to return the current page index based on offset and page size
Pagination component
The "presentation" component is not included in this library, because it's likely going to look very different in each app, however, you can find an example implementation at example/components/Pagination/index.tsx
Tree shaking
To enable tree shaking and save some space you can import functions like so: