state-in-url 4.0.3 → 4.0.4
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.md
CHANGED
|
@@ -23,6 +23,7 @@ English | [한국어](./README.KO.md) | [简体中文](./README.CN.md)
|
|
|
23
23
|
[](https://github.com/asmyshlyaev177/state-in-url/)
|
|
24
24
|
[]([https://github.com/semantic-release/semantic-release](https://github.com/asmyshlyaev177/state-in-url))
|
|
25
25
|

|
|
26
|
+
[](https://scorecard.dev/viewer/?uri=github.com/asmyshlyaev177/state-in-url)
|
|
26
27
|
|
|
27
28
|
</div>
|
|
28
29
|
|
|
@@ -53,7 +54,7 @@ Share if it useful for you.
|
|
|
53
54
|
|
|
54
55
|
# Why use `state-in-url`?
|
|
55
56
|
|
|
56
|
-
Store any user state in query parameters; imagine JSON in a browser URL, while keeping types and structure of data.
|
|
57
|
+
Store any user state in query parameters; imagine JSON in a browser URL, while keeping types and structure of data, e.g. numbers will be decoded as numbers not strings, Date stay a date, objects and arrays supported.
|
|
57
58
|
Dead simple, fast, and with static Typescript validation. Deep links, aka URL synchronization, made easy.
|
|
58
59
|
|
|
59
60
|
Contains `useUrlState` hook for Next.js and react-router, and helpers for anything else on JS.
|
|
@@ -131,7 +132,7 @@ All components that use the same `state` object are automatically synchronized.
|
|
|
131
132
|
|
|
132
133
|
## useUrlState hook for Next.js
|
|
133
134
|
|
|
134
|
-
[Docs](packages/urlstate/next/useUrlState#api)
|
|
135
|
+
[Full API Docs](packages/urlstate/next/useUrlState#api)
|
|
135
136
|
|
|
136
137
|
[React-Router example](#useurlstate-hook-for-react-router)
|
|
137
138
|
|
|
@@ -397,7 +398,7 @@ function SettingsComponent() {
|
|
|
397
398
|
|
|
398
399
|
API is same as for Next.js version, except can pass options from [NavigateOptions](https://github.com/remix-run/react-router/blob/bc693ed9f39170bda13b9e1b282fb8e9d5925f66/packages/react-router/lib/context.ts#L99) type.
|
|
399
400
|
|
|
400
|
-
[Docs](packages/urlstate/react-router/useUrlState#api)
|
|
401
|
+
[API Docs](packages/urlstate/react-router/useUrlState#api)
|
|
401
402
|
|
|
402
403
|
### Example
|
|
403
404
|
|
|
@@ -486,7 +487,7 @@ const tags = [
|
|
|
486
487
|
|
|
487
488
|
Hooks to create your own `useUrlState` hooks with other routers, e.g. react-router or tanstack router.
|
|
488
489
|
|
|
489
|
-
[Docs](packages/urlstate/useUrlStateBase)
|
|
490
|
+
[API Docs](packages/urlstate/useUrlStateBase)
|
|
490
491
|
|
|
491
492
|
## `useSharedState` hook for React.js
|
|
492
493
|
|
|
@@ -503,19 +504,19 @@ function SettingsComponent() {
|
|
|
503
504
|
}
|
|
504
505
|
```
|
|
505
506
|
|
|
506
|
-
[Docs](packages/urlstate/useSharedState/README.md)
|
|
507
|
+
[API Docs](packages/urlstate/useSharedState/README.md)
|
|
507
508
|
|
|
508
509
|
## `useUrlEncode` hook for React.js
|
|
509
510
|
|
|
510
|
-
[Docs](packages/urlstate/useUrlEncode/README.md)
|
|
511
|
+
[API Docs](packages/urlstate/useUrlEncode/README.md)
|
|
511
512
|
|
|
512
513
|
## `encodeState` and `decodeState` helpers
|
|
513
514
|
|
|
514
|
-
[Docs](packages/urlstate/encodeState/README.md)
|
|
515
|
+
[API Docs](packages/urlstate/encodeState/README.md)
|
|
515
516
|
|
|
516
517
|
## `encode` and `decode` helpers
|
|
517
518
|
|
|
518
|
-
[Docs](packages/urlstate/encoder/README.md)
|
|
519
|
+
[API Docs](packages/urlstate/encoder/README.md)
|
|
519
520
|
|
|
520
521
|
# Best Practices
|
|
521
522
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRouter as t,useSearchParams as e}from"next/navigation";import r from"react";import{parseSPObj as a}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as o,isSSR as m,filterUnknownParams as u,filterUnknownParamsClient as i}from"../../utils.mjs";function l({defaultState:l,searchParams:c,useHistory:n
|
|
1
|
+
import{useRouter as t,useSearchParams as e}from"next/navigation";import r from"react";import{parseSPObj as a}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as o,isSSR as m,filterUnknownParams as u,filterUnknownParamsClient as i}from"../../utils.mjs";function l({defaultState:l,searchParams:c,useHistory:f,...n}){const S=void 0===f||f?o:t(),{state:d,updateState:j,updateUrl:U,getState:b}=s(l,S,(({parse:t})=>m()?a(u(l,c),l):t(i(l)))),g=r.useCallback(((t,e)=>U(t,{...p,...n,...e})),[U,n]),v=e();return r.useEffect((()=>{j(u(l,a(Object.fromEntries([...v.entries()]),l)))}),[v]),{setState:j,updateState:j,setUrl:g,updateUrl:g,urlState:d,state:d,getState:b}}const p={replace:!0,scroll:!1};export{l as useUrlState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"react";import{useNavigate as e,useSearchParams as r}from"react-router-dom";import{parseSPObj as a}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as o,filterUnknownParamsClient as u,assignValue as m,filterUnknownParams as p}from"../../utils.mjs";function l({defaultState:l,useHistory:S,...f}){const i=e(),n=t.useMemo((()=>S?o:{replace:(t,e)=>i(t,{...c,...f,...e}),push:(t,e)=>i(t,{...c,...f,...e})}),[i,f]),{state:d,updateState:j,updateUrl:U,getState:b}=s(l,n,(({parse:t})=>t(u(l)))),g=t.useCallback(((t,e)=>{
|
|
1
|
+
import t from"react";import{useNavigate as e,useSearchParams as r}from"react-router-dom";import{parseSPObj as a}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as o,filterUnknownParamsClient as u,assignValue as m,filterUnknownParams as p}from"../../utils.mjs";function l({defaultState:l,useHistory:S,...f}){const i=e(),n=t.useMemo((()=>S?o:{replace:(t,e)=>i(t,{...c,...f,...e}),push:(t,e)=>i(t,{...c,...f,...e})}),[i,f]),{state:d,updateState:j,updateUrl:U,getState:b}=s(l,n,(({parse:t})=>t(u(l)))),g=t.useCallback(((t,e)=>U(t,{...c,...f,...e})),[f]),[B]=r();return t.useEffect((()=>{j(m(l,d,p(l,a(Object.fromEntries([...B.entries()]),l))))}),[B]),{setState:j,updateState:j,setUrl:g,updateUrl:g,urlState:d,state:d,getState:b}}const c={replace:!0,preventScrollReset:!0};export{l as useUrlState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"react";import{stateMap as r,subscribers as e}from"../subscribers.mjs";import{useInsertionEffect as n}from"../useInsertionEffect.mjs";import{isSSR as u,isEqual as c}from"../utils.mjs";function s(s,o){const f=t.useRef(s),[a,i]=t.useState((()=>{if(u())return o?o?.():f.current;const t=r.get(f.current);if(t)return t;{const t=o?.()||f.current;return r.set(f.current,t),t}})),m=t.useCallback((t=>{const n=r.get(f.current),u="function"==typeof t?t(n):{...n,...t};c(n,u)||(r.set(f.current,u),e.get(f.current).forEach((t=>
|
|
1
|
+
import t from"react";import{stateMap as r,subscribers as e}from"../subscribers.mjs";import{useInsertionEffect as n}from"../useInsertionEffect.mjs";import{isSSR as u,isEqual as c}from"../utils.mjs";function s(s,o){const f=t.useRef(s),[a,i]=t.useState((()=>{if(u())return o?o?.():f.current;const t=r.get(f.current);if(t)return t;{const t=o?.()||f.current;return r.set(f.current,t),t}})),m=t.useCallback((t=>{const n=r.get(f.current),u="function"==typeof t?t(n):{...n,...t};c(n,u)||(r.set(f.current,u),e.get(f.current).forEach((t=>t())))}),[]);n((()=>{const t=e.add(f.current,(()=>{i(r.get(f.current)||f.current)}));return()=>{t()}}),[]);return{state:a,getState:t.useCallback((()=>r.get(f.current)||f.current),[]),setState:m}}export{s as useSharedState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"react";import{encodeState as
|
|
1
|
+
import t from"react";import{encodeState as e,decodeState as o}from"../encodeState/encodeState.mjs";import{typeOf as r}from"../utils.mjs";function a(a){const c=t.useCallback(((t,o)=>"object"===r(t)?e(t,a,o):""),[a]);return{parse:t.useCallback((t=>o(t,a)),[a]),stringify:c}}export{a as useUrlEncode};
|
package/package.json
CHANGED
|
@@ -1,32 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
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
5
|
"homepage": "https://state-in-url.dev",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"front-end",
|
|
8
|
-
"state-management",
|
|
9
|
-
"state management",
|
|
10
|
-
"deep links",
|
|
11
|
-
"deep linking",
|
|
12
|
-
"url synchronization",
|
|
13
|
-
"useUrlState",
|
|
14
|
-
"state in url",
|
|
15
|
-
"client components communication",
|
|
16
|
-
"query string",
|
|
17
|
-
"search params",
|
|
18
|
-
"query params",
|
|
19
|
-
"typescript",
|
|
20
|
-
"workflow",
|
|
21
|
-
"javascript",
|
|
22
|
-
"hooks",
|
|
23
|
-
"react.js",
|
|
24
|
-
"reactjs",
|
|
25
|
-
"react",
|
|
26
|
-
"NextJS",
|
|
27
|
-
"Next.js",
|
|
28
|
-
"nuqs alternative"
|
|
29
|
-
],
|
|
30
6
|
"repository": {
|
|
31
7
|
"type": "git",
|
|
32
8
|
"url": "git+https://github.com/asmyshlyaev177/state-in-url.git"
|
|
@@ -402,5 +378,31 @@
|
|
|
402
378
|
"wait-on": "^8.0.1",
|
|
403
379
|
"wireit": "^0.14.9"
|
|
404
380
|
},
|
|
381
|
+
"keywords": [
|
|
382
|
+
"front-end",
|
|
383
|
+
"state-management",
|
|
384
|
+
"state management",
|
|
385
|
+
"deep links",
|
|
386
|
+
"deep linking",
|
|
387
|
+
"url synchronization",
|
|
388
|
+
"useUrlState",
|
|
389
|
+
"state in url",
|
|
390
|
+
"client components communication",
|
|
391
|
+
"query string",
|
|
392
|
+
"search params",
|
|
393
|
+
"query params",
|
|
394
|
+
"typescript",
|
|
395
|
+
"workflow",
|
|
396
|
+
"javascript",
|
|
397
|
+
"hooks",
|
|
398
|
+
"react.js",
|
|
399
|
+
"reactjs",
|
|
400
|
+
"react",
|
|
401
|
+
"NextJS",
|
|
402
|
+
"Next.js",
|
|
403
|
+
"nuqs alternative",
|
|
404
|
+
"query params parser",
|
|
405
|
+
"query params parsing"
|
|
406
|
+
],
|
|
405
407
|
"packageManager": "npm@10.8.2"
|
|
406
408
|
}
|