state-in-url 4.1.4 → 4.1.5
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
|
@@ -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;
|
|
@@ -46,9 +52,46 @@ 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
|
+
* // can pass optional React-Router `NavigateOptions`
|
|
66
|
+
* setState(curr => ({ ...curr, name: 'test' }) );
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updatestate}
|
|
70
|
+
*/
|
|
50
71
|
setState: (value: Partial<T> | ((currState: T) => T)) => void;
|
|
72
|
+
/**
|
|
73
|
+
* * Example:
|
|
74
|
+
* ```ts
|
|
75
|
+
* setUrl({ name: 'test' });
|
|
76
|
+
* // or
|
|
77
|
+
* setUrl(curr => ({ ...curr, name: 'test' }), { replace: true } );
|
|
78
|
+
* // can pass optional React-Router `NavigateOptions`
|
|
79
|
+
* setUrl(curr => ({ ...curr, name: 'test' }), { preventScrollReset: false } );
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updateurl}
|
|
83
|
+
*/
|
|
51
84
|
setUrl: (value?: Partial<T> | ((currState: T) => T), options?: Params) => void;
|
|
85
|
+
/**
|
|
86
|
+
* * Example:
|
|
87
|
+
* ```ts
|
|
88
|
+
* reset();
|
|
89
|
+
* // or
|
|
90
|
+
* reset({ replace: false, preventScrollReset: false })
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#reset}
|
|
94
|
+
*/
|
|
52
95
|
reset: (options?: NavigateOptions & {
|
|
53
96
|
[key: string]: unknown;
|
|
54
97
|
}) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.5",
|
|
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
6
|
"repository": {
|