state-in-url 4.1.4 → 4.1.6

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
@@ -43,7 +43,7 @@ English | [한국어](./README.KO.md) | [简体中文](./README.CN.md)
43
43
 
44
44
  <hr />
45
45
 
46
- Add a ⭐️ and <a href="https://github.com/asmyshlyaev177" target="_blank">follow me</a> to support the project!
46
+ Add a <a href="#"><img src="https://raw.githubusercontent.com/acervenky/animated-github-badges/master/assets/starbadge.gif" width="25" height="25"></a> and <a href="https://github.com/asmyshlyaev177" target="_blank">follow me</a> to support the project!
47
47
 
48
48
  Will appreciate you feedback/opinion on [discussions](https://github.com/asmyshlyaev177/state-in-url/discussions/1)
49
49
 
@@ -85,12 +85,13 @@ This library is a good alternative for NUQS.
85
85
  - ✨ **Complex data**: Nested objects, dates and arrays, works same as JSON, but in URL
86
86
  - ☂ **Default values**: Giving you default values if parameter not in url
87
87
  - ⌨ **Organized**: All possible values defined at start, protect you from getting non existing key
88
+ - **flexible**: Can use more than 1 state objects on the same page, just use different keys
88
89
  - **Fast**: Minimal rerenders, around [1ms](https://github.com/asmyshlyaev177/state-in-url/blob/87c8c7c995c5cd7d9e7aa039c30bfe64b24abe4b/packages/urlstate/encoder/encoder.test.ts#L185) to encode and decode big object
89
90
  - **Server Side Rendering**: Can use it in Server Components, Next.js 14 and 15 are supported
90
91
  - **Lightweight**: Zero dependencies, library less than 2KB
91
92
  - **DX**: Good developer experience, documentation, JSDoc comments, and examples
92
93
  - **Framework Flexibility**: Hooks for `Next.js` and `react-router`, helpers to use it with other frameworks or pure JS
93
- - **Well tested**: Unit tests and Playwright tests for Chrome/Firefox/Safari
94
+ - **Well tested**: [Unit tests and Playwright tests for Chrome/Firefox/Safari](https://github.com/asmyshlyaev177/state-in-url/actions/workflows/tests.yml)
94
95
  - **Permissive license**: MIT
95
96
 
96
97
  ## Table of content
@@ -7,10 +7,19 @@ import { type JSONCompatible } from "../../utils";
7
7
  * .
8
8
  */
9
9
  export declare function useUrlState<T extends JSONCompatible>({ defaultState: T, searchParams, replace, scroll, useHistory, }: OldParams<T>): {
10
+ /**
11
+ * @deprecated use `urlState`
12
+ */
10
13
  state: T;
11
14
  urlState: T;
15
+ /**
16
+ * @deprecated use `setState`
17
+ */
12
18
  updateState: (value: Partial<T> | ((currState: T) => T)) => void;
13
19
  setState: (value: Partial<T> | ((currState: T) => T)) => void;
20
+ /**
21
+ * @deprecated use `setUrl`
22
+ */
14
23
  updateUrl: (value?: Partial<T> | ((currState: T) => T)) => void;
15
24
  setUrl: (value?: Partial<T> | ((currState: T) => T)) => void;
16
25
  };
@@ -49,9 +58,42 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState: T,
49
58
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState}
50
59
  */
51
60
  export declare function useUrlState<T extends JSONCompatible>(defaultState: T, params?: Params): {
61
+ /**
62
+ * State object. Don't mutate directly, use `setState` or `setUrl`
63
+ */
52
64
  urlState: T;
65
+ /**
66
+ * * Example:
67
+ * ```ts
68
+ * setState({ name: 'test' });
69
+ * // or
70
+ * setState(curr => ({ ...curr, name: 'test' }) );
71
+ * ```
72
+ *
73
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState#updatestate}
74
+ */
53
75
  setState: (value: Partial<T> | ((currState: T) => T)) => void;
76
+ /**
77
+ * * Example:
78
+ * ```ts
79
+ * setUrl({ name: 'test' });
80
+ * // or
81
+ * setUrl(curr => ({ ...curr, name: 'test' }), { replace: true, scroll: false } );
82
+ * ```
83
+ *
84
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState#updateurl}
85
+ */
54
86
  setUrl: (value?: Partial<T> | ((currState: T) => T), options?: Options) => void;
87
+ /**
88
+ * * Example:
89
+ * ```ts
90
+ * reset();
91
+ * // or
92
+ * reset({ replace: false, scroll: true })
93
+ * ```
94
+ *
95
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState#reset}
96
+ */
55
97
  reset: (options?: Options & {
56
98
  [key: string]: unknown;
57
99
  }) => void;
@@ -7,8 +7,14 @@ import { type JSONCompatible } from "../../utils";
7
7
  * .
8
8
  */
9
9
  export declare function useUrlState<T extends JSONCompatible>({ defaultState: T, searchParams, replace, useHistory, }: OldParams<T>): {
10
+ /**
11
+ * @deprecated use `urlState`
12
+ */
10
13
  state: T;
11
14
  urlState: T;
15
+ /**
16
+ * @deprecated use `setState`
17
+ */
12
18
  updateState: (value: Partial<T> | ((currState: T) => T)) => void;
13
19
  setState: (value: Partial<T> | ((currState: T) => T)) => void;
14
20
  updateUrl: (value?: Partial<T> | ((currState: T) => T)) => void;
@@ -19,7 +25,7 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState: T,
19
25
  *
20
26
  * @param {JSONCompatible<T>} [defaultState] Fallback (default) values for state
21
27
  * @param {Object} params - Object with other parameters
22
- * @param {NavigateOptions} params.NavigateOptions See type from `react-router-dom`
28
+ * @param {NavigateOptions} params.NavigateOptions See type from [`react-router-dom`](https://api.reactrouter.com/v7/interfaces/react_router.NavigateOptions.html)
23
29
  * @param {boolean} params.replace replace URL or push, default `true`
24
30
  * @param {boolean} params.useHistory use window.history for navigation, default `false`
25
31
  * @param {boolean} params.preventScrollReset keep scroll position, default `true`
@@ -46,9 +52,44 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState: T,
46
52
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState}
47
53
  */
48
54
  export declare function useUrlState<T extends JSONCompatible>(defaultState: T, params?: Params): {
55
+ /**
56
+ * State object. Don't mutate directly, use `setState` or `setUrl`
57
+ */
49
58
  urlState: T;
59
+ /**
60
+ * * Example:
61
+ * ```ts
62
+ * setState({ name: 'test' });
63
+ * // or
64
+ * setState(curr => ({ ...curr, name: 'test' }) );
65
+ * ```
66
+ *
67
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updatestate}
68
+ */
50
69
  setState: (value: Partial<T> | ((currState: T) => T)) => void;
70
+ /**
71
+ * * Example:
72
+ * ```ts
73
+ * setUrl({ name: 'test' });
74
+ * // or
75
+ * setUrl(curr => ({ ...curr, name: 'test' }), { replace: true } );
76
+ * // can pass optional React-Router `NavigateOptions`
77
+ * setUrl(curr => ({ ...curr, name: 'test' }), { preventScrollReset: false } );
78
+ * ```
79
+ *
80
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updateurl}
81
+ */
51
82
  setUrl: (value?: Partial<T> | ((currState: T) => T), options?: Params) => void;
83
+ /**
84
+ * * Example:
85
+ * ```ts
86
+ * reset();
87
+ * // or
88
+ * reset({ replace: false, preventScrollReset: false })
89
+ * ```
90
+ *
91
+ * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#reset}
92
+ */
52
93
  reset: (options?: NavigateOptions & {
53
94
  [key: string]: unknown;
54
95
  }) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "state-in-url",
3
- "version": "4.1.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.",
3
+ "version": "4.1.6",
4
+ "description": "Store state in URL as in object, types and structure are preserved, with TS validation. Same API as React.useState, wthout any hasssle or boilerplate. Next.js@14-15 and react-router@6-7.",
5
5
  "homepage": "https://state-in-url.dev",
6
6
  "repository": {
7
7
  "type": "git",
@@ -388,30 +388,57 @@
388
388
  "wireit": "^0.14.9"
389
389
  },
390
390
  "keywords": [
391
- "front-end",
392
- "state-management",
391
+ "state in url",
392
+ "useSearchParams",
393
+ "useUrlState",
394
+ "url state",
395
+ "search params",
396
+ "nuqs alternative",
397
+ "reactive",
398
+ "json",
399
+ "state sync",
393
400
  "state management",
394
- "deep links",
395
- "deep linking",
401
+ "encode",
402
+ "decode",
403
+ "Next.js",
404
+ "react-router",
405
+ "url",
396
406
  "url synchronization",
397
- "useUrlState",
398
- "state in url",
407
+ "url sync",
408
+ "state synchronization",
409
+ "synchronized state",
410
+ "state-in-url",
411
+ "store",
412
+ "react hook",
413
+ "state hook",
414
+ "url-state",
399
415
  "client components communication",
400
416
  "query string",
401
- "search params",
417
+ "query-string",
418
+ "querystring",
419
+ "search-params",
420
+ "searchparams",
421
+ "params",
422
+ "parse",
423
+ "stringify",
402
424
  "query params",
403
425
  "typescript",
404
- "workflow",
405
- "javascript",
406
426
  "hooks",
407
427
  "react.js",
408
428
  "reactjs",
409
429
  "react",
410
430
  "NextJS",
411
- "Next.js",
412
- "nuqs alternative",
413
431
  "query params parser",
414
- "query params parsing"
432
+ "query params parsing",
433
+ "shared state",
434
+ "state sharing",
435
+ "front-end",
436
+ "state-management",
437
+ "state-sync",
438
+ "search",
439
+ "encode url",
440
+ "decode url",
441
+ "fast"
415
442
  ],
416
443
  "packageManager": "npm@10.8.2"
417
444
  }