state-in-url 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.CN.md +1 -1
- package/README.KO.md +1 -1
- package/README.md +34 -4
- package/package.json +2 -2
package/README.CN.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|

|
|
24
24
|
|
|
25
|
-
<a href="https://state-in-url
|
|
25
|
+
<a href="https://state-in-url.dev/" target="_blank">演示</a> |
|
|
26
26
|
<a href="https://state-in-url.netlify.app/" target="_blank">DEMO2</a> |
|
|
27
27
|
|
|
28
28
|
<hr />
|
package/README.KO.md
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|

|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
<a href="https://state-in-url
|
|
29
|
+
<a href="https://state-in-url.dev" target="_blank">데모</a> |
|
|
30
30
|
<a href="https://state-in-url.netlify.app/" target="_blank">DEMO2</a> |
|
|
31
31
|
|
|
32
32
|
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ English | [한국어](./README.KO.md) | [简体中文](./README.CN.md)
|
|
|
31
31
|
|
|
32
32
|

|
|
33
33
|
|
|
34
|
-
<a href="https://state-in-url
|
|
34
|
+
<a href="https://state-in-url.dev" target="_blank">DEMO</a> |
|
|
35
35
|
<a href="https://state-in-url.netlify.app/" target="_blank">DEMO2</a>
|
|
36
36
|
|
|
37
37
|
<hr />
|
|
@@ -119,6 +119,8 @@ Possibly need to set `"module": "ES2022"`, or `"module": "ESNext"`
|
|
|
119
119
|
|
|
120
120
|
[Docs](packages/urlstate/next/useUrlState#api)
|
|
121
121
|
|
|
122
|
+
[React-Router example](#useurlstate-hook-for-react-router)
|
|
123
|
+
|
|
122
124
|
### Usage examples
|
|
123
125
|
|
|
124
126
|
#### Basic
|
|
@@ -177,6 +179,9 @@ function MyComponent() {
|
|
|
177
179
|
|
|
178
180
|
#### With complex state shape
|
|
179
181
|
|
|
182
|
+
<details>
|
|
183
|
+
<Summary>Example</Summary>
|
|
184
|
+
|
|
180
185
|
```typescript
|
|
181
186
|
export const form: Form = {
|
|
182
187
|
name: '',
|
|
@@ -191,7 +196,6 @@ type Form = {
|
|
|
191
196
|
'agree to terms': boolean;
|
|
192
197
|
tags: { id: string; value: { text: string; time: Date } }[];
|
|
193
198
|
};
|
|
194
|
-
|
|
195
199
|
```
|
|
196
200
|
|
|
197
201
|
```typescript
|
|
@@ -251,10 +255,16 @@ const tags = [
|
|
|
251
255
|
```
|
|
252
256
|
|
|
253
257
|
[Demo page example code](https://github.com/asmyshlyaev177/state-in-url/blob/master/packages/example-nextjs14/src/app/Form.tsx)
|
|
258
|
+
</details>
|
|
259
|
+
|
|
254
260
|
|
|
255
261
|
#### Auto sync state
|
|
256
262
|
|
|
257
|
-
|
|
263
|
+
<details>
|
|
264
|
+
<Summary>Example</Summary>
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
|
|
258
268
|
const timer = React.useRef(0 as unknown as NodeJS.Timeout);
|
|
259
269
|
React.useEffect(() => {
|
|
260
270
|
clearTimeout(timer.current);
|
|
@@ -275,8 +285,15 @@ Syncing state `onBlur` will be more aligned with real world usage.
|
|
|
275
285
|
<input onBlur={() => updateUrl()} .../>
|
|
276
286
|
```
|
|
277
287
|
|
|
288
|
+
</details>
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
278
292
|
#### With server side rendering
|
|
279
293
|
|
|
294
|
+
<details>
|
|
295
|
+
<Summary>Example</Summary>
|
|
296
|
+
|
|
280
297
|
```typescript
|
|
281
298
|
export default async function Home({ searchParams }: { searchParams: object }) {
|
|
282
299
|
return (
|
|
@@ -295,9 +312,13 @@ const Form = ({ searchParams }: { searchParams: object }) => {
|
|
|
295
312
|
}
|
|
296
313
|
```
|
|
297
314
|
|
|
315
|
+
</details>
|
|
316
|
+
|
|
298
317
|
#### Using hook in `layout` component
|
|
299
318
|
|
|
300
|
-
|
|
319
|
+
<details>
|
|
320
|
+
<Summary>Example</Summary>
|
|
321
|
+
That a tricky part, since nextjs with app router doesn't allow to access searchParams from server side. There is workaround with using middleware, but it isn't pretty and can stop working after nextjs update.
|
|
301
322
|
|
|
302
323
|
```typescript
|
|
303
324
|
// add to appropriate `layout.tsc`
|
|
@@ -341,9 +362,13 @@ export default async function Layout({
|
|
|
341
362
|
|
|
342
363
|
|
|
343
364
|
```
|
|
365
|
+
</details>
|
|
344
366
|
|
|
345
367
|
#### With arbitrary state shape (not recommended)
|
|
346
368
|
|
|
369
|
+
<details>
|
|
370
|
+
<Summary>Example</Summary>
|
|
371
|
+
|
|
347
372
|
```typescript
|
|
348
373
|
'use client'
|
|
349
374
|
import { useUrlState } from 'state-in-url/next';
|
|
@@ -354,6 +379,9 @@ function SettingsComponent() {
|
|
|
354
379
|
const { state, updateUrl, updateState } = useUrlState<object>(someObj);
|
|
355
380
|
}
|
|
356
381
|
```
|
|
382
|
+
</details>
|
|
383
|
+
|
|
384
|
+
|
|
357
385
|
|
|
358
386
|
## useUrlState hook for React-Router
|
|
359
387
|
|
|
@@ -513,6 +541,8 @@ This project is licensed under the [MIT license](LICENSE).
|
|
|
513
541
|
|
|
514
542
|
## Inspiration
|
|
515
543
|
|
|
544
|
+
[NUQS](https://github.com/47ng/nuqs)
|
|
545
|
+
|
|
516
546
|
[Using URL to store state in Vue](https://dev.to/jacobandrewsky/using-url-to-store-state-in-vue-275c)
|
|
517
547
|
|
|
518
548
|
[Storing state in the URL](https://antonz.org/storing-state/)
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Easily share complex state objects between unrelated React components, preserve types and structure, with TS validation. Deep links and url state synchronization wthout any hasssle or boilerplate.",
|
|
5
|
-
"homepage": "https://state-in-url
|
|
5
|
+
"homepage": "https://state-in-url.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"front-end",
|
|
8
8
|
"state-management",
|