You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[React-Router based pagination](#react-router-based-pagination)
17
-
-[NextJS Router based pagination](#nextjs-router-based-pagination)
12
+
-[useQuery](#usequery)
13
+
-[usePagination](#usepagination)
14
+
-[useQueryAndPagination](#usequeryandpagination)
18
15
-[Build & Publish](#build--publish)
19
16
-[Information](#information)
20
17
21
18
## Usage
22
19
23
-
First, you have to install the package:
20
+
Install the package:
24
21
25
-
```bash
22
+
```sh
26
23
npm install @aboutbits/react-pagination
27
24
```
28
25
29
-
Second, you can make use of the `useQueryAndPagination` hook. This package implements 3 versions of this hook:
26
+
There are a variety of entry points from which to import the hooks `useQuery`, `usePagiation` and `useQueryAndPagination`:
30
27
31
-
-[In Memory](#in-memory-pagination): Use this hook where you don't want to modify browser history. e.g. Dialogs
32
-
-[React Router](#react-router-based-pagination): Use this hook if you want to keep track of the state in the URL and
33
-
your project is using React Router.
34
-
-[NextJS Router](#nextjs-router-based-pagination): Use this hook if you want to keep track of the state in the URL and
35
-
your project is using NextJS.
28
+
- For the [Next.js](https://nextjs.org/) router:
29
+
-`@aboutbits/react-pagination/next-router`
30
+
-`@aboutbits/react-pagination/next-router/zod`
31
+
- For [React Router](https://reactrouter.com):
32
+
-`@aboutbits/react-pagination/react-router`
33
+
-`@aboutbits/react-pagination/react-router/zod`
34
+
- For an in-memory router that does not modify the browser history:
35
+
-`@aboutbits/react-pagination/in-memory`
36
+
-`@aboutbits/react-pagination/in-memory/zod`
36
37
37
-
### useQueryAndPagination
38
+
The hooks exported from `@aboutbits/react-pagination/*/zod` are more convenient when using [zod](https://github.com/colinhacks/zod) for the validation of the query.
38
39
39
-
This hook supports the combination of query parameters and pagination and manages the state of the query parameter values and the
40
-
pagination values.
40
+
`useQueryAndPagination` merges the functionality of `useQuery` and `usePagination`. Changing the query resets the page, but changing the page does not reset the query.
41
41
42
-
#### The hook supports following configuration parameter object:
42
+
Some examples follow, but we recommend having a look at the type definitions for more details about the API.
43
43
44
-
|value|type|default|description|
45
-
|---|---|---|---|
46
-
|indexType|IndexType|IndexType.ZERO_BASED|It defines whether the pagination is zero or one based.|
47
-
|pageSize|number|15|Page size of the pagination.|
48
-
|defaultQueryParameters/Record<string, string>|{}|It defines the default value for each query parameter. This is used to remove a query parameter from the URL and also to clear the query.
49
-
50
-
#### The hook returns the following object:
51
-
52
-
|value|type|description|
53
-
|---|---|---|
54
-
|queryParameters|object|values of your query parameters|
55
-
|page|number|value of the current page|
56
-
|size|number|max elements in a single page|
57
-
|actions|object|object with 3 functions: updateQuery, setPage, clear|
0 commit comments