Skip to content

Commit f41703c

Browse files
feat: ✨ enable async parameter setting in query param store and update related tests
1 parent 6193df0 commit f41703c

File tree

7 files changed

+109
-86
lines changed

7 files changed

+109
-86
lines changed

examples/next/src/console.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const Console: React.FC<ConsoleProps> = () => {
1313
{JSON.stringify(params, null, 2)}
1414
</pre>
1515
<button
16-
onClick={() => setParams({ search: 'test' })}
16+
onClick={async () => {
17+
await setParams({ search: 'test' })
18+
}}
1719
className="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors"
1820
>
1921
Set Search to "test"

examples/next/src/pages/[...slug].tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ export default function Home() {
1717
<input
1818
type="text"
1919
value={params.search ?? ''}
20-
onChange={(e) => setParams({ search: e.target.value })}
20+
onChange={async (e) => {
21+
await setParams({ search: e.target.value })
22+
}}
2123
placeholder="Search"
2224
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
2325
/>
2426
<input
2527
type="number"
2628
value={params.page ?? ''}
27-
onChange={(e) => setParams({ page: parseInt(e.target.value, 10) })}
29+
onChange={async (e) => {
30+
await setParams({ page: parseInt(e.target.value, 10) })
31+
}}
2832
placeholder="Page"
2933
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
3034
/>

examples/next/src/pages/defaults.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ export default function Home() {
1919
<input
2020
type="text"
2121
value={params.search ?? ''}
22-
onChange={(e) => setParams({ search: e.target.value })}
22+
onChange={async (e) => {
23+
await setParams({ search: e.target.value })
24+
}}
2325
placeholder="Search"
2426
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
2527
/>
2628
<input
2729
type="number"
2830
value={params.page ?? ''}
29-
onChange={(e) => setParams({ page: parseInt(e.target.value, 10) })}
31+
onChange={async (e) => {
32+
await setParams({ page: parseInt(e.target.value, 10) })
33+
}}
3034
placeholder="Page"
3135
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
3236
/>

examples/next/src/pages/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ export default function Home() {
1818
<input
1919
type="text"
2020
value={params.search ?? ''}
21-
onChange={(e) => setParams({ search: e.target.value })}
21+
onChange={async (e) => {
22+
await setParams({ search: e.target.value })
23+
}}
2224
placeholder="Search"
2325
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
2426
/>
2527
<input
2628
type="number"
2729
value={params.page ?? ''}
28-
onChange={(e) => setParams({ page: parseInt(e.target.value, 10) })}
30+
onChange={async (e) => {
31+
await setParams({ page: parseInt(e.target.value, 10) })
32+
}}
2933
placeholder="Page"
3034
className="px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
3135
/>

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ It requires you to have the following packages pre-installed at minimum in your
5151
```
5252

5353
> Note: It may work with older versions of the packages above too. I have personally tested it with Next 12.0.0 and it worked.
54+
## Features & Use Cases
5455

55-
## Features
56-
56+
### Core Features
5757
- Manage application state using URL query parameters
5858
- Type-safe with Zod schema validation
5959
- Seamless integration with Next.js Router. **Support for other routers will come soon.**
@@ -62,12 +62,10 @@ It requires you to have the following packages pre-installed at minimum in your
6262
- Performs shallow routing by default but this is customizable for the entire store or just on a per-use basis.
6363
- Server-side rendering support
6464
- Allows you to specify initial query values when the router itself is not ready.
65-
- Listens for URL updates outside of the hooks and makes sure its own stateis always up to date.
65+
- Listens for URL updates outside of the hooks and makes sure its own state is always up to date.
6666
- The library internally does shallow comparisons to prevent unnecessary re-renders.
6767

68-
## Usage
69-
70-
`react-url-query-parameter-store` caters to a variety of use-cases.
68+
### Common Use Cases
7169

7270
1. **State Persistence**: Store application state in the URL for easy sharing and bookmarking.
7371
2. **User Preferences**: Manage user settings like language, theme, or view options.
@@ -85,6 +83,8 @@ It requires you to have the following packages pre-installed at minimum in your
8583
14. **Wizard Steps**: Track progress in multi-step processes or wizards.
8684
15. **Conditional Rendering**: Toggle visibility of components based on URL parameters.
8785

86+
### Examples
87+
8888
```tsx
8989
import { z } from "zod";
9090
import { useRouter } from 'next/router';

0 commit comments

Comments
 (0)