state-in-url 4.0.0 → 4.0.1
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
|
@@ -146,7 +146,7 @@ import { userState } from './userState';
|
|
|
146
146
|
function MyComponent() {
|
|
147
147
|
// can pass `replace` arg, it's control will `setUrl` will use `rounter.push` or `router.replace`, default replace=true
|
|
148
148
|
// can pass `searchParams` from server components
|
|
149
|
-
const { urlState, setUrl,
|
|
149
|
+
const { urlState, setUrl, setState } = useUrlState({ defaultState: userState });
|
|
150
150
|
|
|
151
151
|
// won't let you to accidently mutate state directly, requires TS
|
|
152
152
|
// urlState.name = 'John' // <- error
|
|
@@ -162,7 +162,7 @@ function MyComponent() {
|
|
|
162
162
|
|
|
163
163
|
// same api as React.useState
|
|
164
164
|
<input value={urlState.name}
|
|
165
|
-
onChange={(ev) => {
|
|
165
|
+
onChange={(ev) => { setState(curr => ({ ...curr, name: ev.target.value })) }}
|
|
166
166
|
// Can update state immediately but sync change to url as needed
|
|
167
167
|
onBlur={() => setUrl()}
|
|
168
168
|
/>
|
|
@@ -185,14 +185,14 @@ function MyComponent() {
|
|
|
185
185
|
export const form: Form = {
|
|
186
186
|
name: '',
|
|
187
187
|
age: undefined,
|
|
188
|
-
|
|
188
|
+
agree_to_terms: false,
|
|
189
189
|
tags: [],
|
|
190
190
|
};
|
|
191
191
|
|
|
192
192
|
type Form = {
|
|
193
193
|
name: string;
|
|
194
194
|
age?: number;
|
|
195
|
-
|
|
195
|
+
agree_to_terms: boolean;
|
|
196
196
|
tags: { id: string; value: { text: string; time: Date } }[];
|
|
197
197
|
};
|
|
198
198
|
```
|
|
@@ -391,14 +391,14 @@ API is same as for Next.js version, except can pass options from [NavigateOption
|
|
|
391
391
|
export const form: Form = {
|
|
392
392
|
name: '',
|
|
393
393
|
age: undefined,
|
|
394
|
-
|
|
394
|
+
agree_to_terms: false,
|
|
395
395
|
tags: [],
|
|
396
396
|
};
|
|
397
397
|
|
|
398
398
|
type Form = {
|
|
399
399
|
name: string;
|
|
400
400
|
age?: number;
|
|
401
|
-
|
|
401
|
+
agree_to_terms: boolean;
|
|
402
402
|
tags: { id: string; value: { text: string; time: Date } }[];
|
|
403
403
|
};
|
|
404
404
|
|
|
@@ -410,7 +410,7 @@ import { useUrlState } from 'state-in-url/react-router';
|
|
|
410
410
|
import { form } from './form';
|
|
411
411
|
|
|
412
412
|
function TagsComponent() {
|
|
413
|
-
const { urlState, setUrl,
|
|
413
|
+
const { urlState, setUrl, setState } = useUrlState({ defaultState: form });
|
|
414
414
|
|
|
415
415
|
const onChangeTags = React.useCallback(
|
|
416
416
|
(tag: (typeof tags)[number]) => {
|
|
@@ -440,7 +440,7 @@ function TagsComponent() {
|
|
|
440
440
|
</Field>
|
|
441
441
|
|
|
442
442
|
<input value={urlState.name}
|
|
443
|
-
onChange={(ev) => {
|
|
443
|
+
onChange={(ev) => { setState(curr => ({ ...curr, name: ev.target.value })) }}
|
|
444
444
|
// Can update state immediately but sync change to url as needed
|
|
445
445
|
onBlur={() => setUrl()}
|
|
446
446
|
/>
|
|
@@ -26,11 +26,11 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState, us
|
|
|
26
26
|
/**
|
|
27
27
|
* * Example:
|
|
28
28
|
* ```ts
|
|
29
|
-
*
|
|
29
|
+
* setState({ name: 'test' });
|
|
30
30
|
* // or
|
|
31
|
-
*
|
|
31
|
+
* setState(curr => ({ ...curr, name: 'test' }) );
|
|
32
32
|
* // can pass optional React-Router `NavigateOptions`
|
|
33
|
-
*
|
|
33
|
+
* setState(curr => ({ ...curr, name: 'test', preventScrollReset: false }) );
|
|
34
34
|
* ```
|
|
35
35
|
*
|
|
36
36
|
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updatestate}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.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.",
|
|
5
5
|
"homepage": "https://state-in-url.dev",
|
|
6
6
|
"keywords": [
|