Skip to content

Commit

Permalink
fix: fix setUrl options as second argument
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Nov 14, 2024
1 parent 518e7bb commit 4b6d277
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/example-nextjs14/src/app/Form-for-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const Form = ({
setState((st) => ({ ...st, age: 18 }));
setUrl(urlState);
setUrl((st) => ({ ...st, age: 18 }));
setUrl(urlState, { replace: true });
setUrl((st) => ({ ...st, age: 18 }), { replace: true });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
2 changes: 2 additions & 0 deletions packages/example-nextjs15/src/app/Form-for-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const Form = ({
setState((st) => ({ ...st, age: 18 }));
setUrl(urlState);
setUrl((st) => ({ ...st, age: 18 }));
setUrl(urlState, { replace: true });
setUrl((st) => ({ ...st, age: 18 }), { replace: true });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
2 changes: 2 additions & 0 deletions packages/example-react-router6/src/Form-for-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const Form = ({ className }: { className?: string }) => {
setState((st) => ({ ...st, age: 18 }));
setUrl(urlState);
setUrl((st) => ({ ...st, age: 18 }));
setUrl(urlState, { replace: true });
setUrl((st) => ({ ...st, age: 18 }), { replace: true });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
5 changes: 4 additions & 1 deletion packages/urlstate/next/useUrlState/useUrlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export function useUrlState<T extends JSONCompatible>(
): {
urlState: T;
setState: (value: Partial<T> | ((currState: T) => T)) => void;
setUrl: (value?: Partial<T> | ((currState: T) => T)) => void;
setUrl: (
value?: Partial<T> | ((currState: T) => T),
options?: Options,
) => void;
};

export function useUrlState<T extends JSONCompatible>(
Expand Down
9 changes: 6 additions & 3 deletions packages/urlstate/react-router/useUrlState/useUrlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export function useUrlState<T extends JSONCompatible>(
): {
urlState: T;
setState: (value: Partial<T> | ((currState: T) => T)) => void;
setUrl: (value?: Partial<T> | ((currState: T) => T)) => void;
setUrl: (
value?: Partial<T> | ((currState: T) => T),
options?: Params,
) => void;
};

export function useUrlState<T extends JSONCompatible>(
Expand Down Expand Up @@ -140,7 +143,7 @@ export function useUrlState<T extends JSONCompatible>(
* // or
* setState(curr => ({ ...curr, name: 'test' }) );
* // can pass optional React-Router `NavigateOptions`
* setState(curr => ({ ...curr, name: 'test', preventScrollReset: false }) );
* setState(curr => ({ ...curr, name: 'test' }) );
* ```
*
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updatestate}
Expand All @@ -157,7 +160,7 @@ export function useUrlState<T extends JSONCompatible>(
* // or
* setUrl(curr => ({ ...curr, name: 'test' }), { replace: true } );
* // can pass optional React-Router `NavigateOptions`
* setState(curr => ({ ...curr, name: 'test', preventScrollReset: false }) );
* setUrl(curr => ({ ...curr, name: 'test' }), { preventScrollReset: false } );
* ```
*
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updateurl}
Expand Down

0 comments on commit 4b6d277

Please sign in to comment.