Skip to content

Commit b450726

Browse files
update readme
1 parent 5c78ef1 commit b450726

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

readme.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
React Pagination
22
=============
33

4-
This package includes pagination hooks for React. The hooks support saving the search and pagination values in local
4+
This package includes pagination hooks for React. The hooks support saving the query and pagination values in local
55
state or in the browser URL.
66

77
## Table of content
88

99
- [Usage](#usage)
10-
- [useSearchAndPagination](#usesearchandpagination)
10+
- [useQueryAndPagination](#usequeryandpagination)
1111
- [Supported Implementations](#supported-implementations)
1212
- [In Memory Pagination](#in-memory-pagination)
1313
- [React-Router based pagination](#react-router-based-pagination)
@@ -23,17 +23,17 @@ First, you have to install the package:
2323
npm install @aboutbits/react-pagination
2424
```
2525

26-
Second, you can make use of the `useSearchAndPagination` hook. This package implements 3 versions of this hook:
26+
Second, you can make use of the `useQueryAndPagination` hook. This package implements 3 versions of this hook:
2727

2828
- [In Memory](#in-memory-pagination): Use this hook where you don't want to modify browser history. e.g. Dialogs
2929
- [React Router](#react-router-based-pagination): Use this hook if you want to keep track of the state in the URL and
3030
your project is using React Router.
3131
- [NextJS Router](#nextjs-router-based-pagination): Use this hook if you want to keep track of the state in the URL and
3232
your project is using NextJS.
3333

34-
### useSearchAndPagination
34+
### useQueryAndPagination
3535

36-
This hook supports the combination of a search value and pagination and manages the state of the search value, and the
36+
This hook supports the combination of query parameters and pagination and manages the state of the query parameter values and the
3737
pagination values.
3838

3939
#### The hook supports following configuration parameter object:
@@ -42,39 +42,40 @@ pagination values.
4242
|---|---|---|---|
4343
|indexType|IndexType|IndexType.ZERO_BASED|It defines whether the pagination is zero or one based.|
4444
|pageSize|number|15|Page size of the pagination.|
45+
|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.
4546

4647
#### The hook returns the following object:
4748

4849
|value|type|description|
4950
|---|---|---|
50-
|search|string|value of your search parameter|
51+
|queryParameters|object|values of your query parameters|
5152
|page|number|value of the current page|
5253
|size|number|max elements in a single page|
53-
|actions|object|object with 3 functions: search, setPage, clear|
54+
|actions|object|object with 3 functions: updateQuery, setPage, clear|
5455

5556
#### Example usage with NextJS
5657

5758
```tsx
58-
import { useSearchAndPagination } from '@aboutbits/react-pagination/dist/nextRouterPagination'
59+
import { useQueryAndPagination } from '@aboutbits/react-pagination/dist/nextRouterPagination'
5960

6061
const users = [
6162
'Alex', 'Simon', 'Natan', 'Nadia', 'Moritz', 'Marie'
6263
]
6364

6465
function UserList() {
65-
const { page, size, search, actions } = useSearchAndPagination({pageSize: 2})
66+
const { page, size, queryParameters, actions } = useQueryAndPagination({pageSize: 2})
6667

6768
return (
6869
<div>
69-
<input onChange={(value) => actions.search(value)}/>
70+
<input onChange={(value) => actions.updateQuery({search: value})}/>
7071
<button onClick={() => actions.clear()}>Clear Input</button>
7172
<select onSelect={(value) => actions.setPage(value)}>
7273
<option value={0}>First Page</option>
7374
<option value={1}>Second Page</option>
7475
</select>
7576

7677
<ul>
77-
{users.filter(user => user.startsWith(search))
78+
{users.filter(user => user.startsWith(queryParameters.search))
7879
.slice(page, page + size)
7980
.map(user => <li>{user}</li>)}
8081
</ul>
@@ -96,15 +97,15 @@ This package includes 3 different implementations of the above hook.
9697
Use this pagination hook if you want to keep track of the pagination in memory. This is very handy for dialogs.
9798

9899
```tsx
99-
import { useSearchAndPagination } from '@aboutbits/react-pagination/dist/inMemoryPagination'
100+
import { useQueryAndPagination } from '@aboutbits/react-pagination/dist/inMemoryPagination'
100101
```
101102

102103
### React-Router based pagination
103104

104105
These are specific hooks for applications that use [React Router](https://reactrouter.com/) for routing.
105106

106107
```tsx
107-
import { useSearchAndPagination } from '@aboutbits/react-pagination/dist/reactRouterPagination'
108+
import { useQueryAndPagination } from '@aboutbits/react-pagination/dist/reactRouterPagination'
108109
```
109110

110111
### NextJS Router based pagination
@@ -113,7 +114,7 @@ These are specific hooks for applications that use [NextJS Router](https://nextj
113114
for routing.
114115

115116
```tsx
116-
import { useSearchAndPagination } from '@aboutbits/react-pagination/dist/nextRouterPagination'
117+
import { useQueryAndPagination } from '@aboutbits/react-pagination/dist/nextRouterPagination'
117118
```
118119

119120
## Build & Publish

0 commit comments

Comments
 (0)