diff --git a/packages/example-nextjs14/src/app/Form-for-test.tsx b/packages/example-nextjs14/src/app/Form-for-test.tsx index bd6d4b1..8eeb9b4 100644 --- a/packages/example-nextjs14/src/app/Form-for-test.tsx +++ b/packages/example-nextjs14/src/app/Form-for-test.tsx @@ -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 }, []); diff --git a/packages/example-nextjs15/src/app/Form-for-test.tsx b/packages/example-nextjs15/src/app/Form-for-test.tsx index 29cbee2..23a9229 100644 --- a/packages/example-nextjs15/src/app/Form-for-test.tsx +++ b/packages/example-nextjs15/src/app/Form-for-test.tsx @@ -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 }, []); diff --git a/packages/example-react-router6/src/Form-for-test.tsx b/packages/example-react-router6/src/Form-for-test.tsx index 2cd7c90..cbc620b 100644 --- a/packages/example-react-router6/src/Form-for-test.tsx +++ b/packages/example-react-router6/src/Form-for-test.tsx @@ -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 }, []); diff --git a/packages/urlstate/next/useUrlState/useUrlState.ts b/packages/urlstate/next/useUrlState/useUrlState.ts index b02e0df..d084a87 100644 --- a/packages/urlstate/next/useUrlState/useUrlState.ts +++ b/packages/urlstate/next/useUrlState/useUrlState.ts @@ -63,7 +63,10 @@ export function useUrlState( ): { urlState: T; setState: (value: Partial | ((currState: T) => T)) => void; - setUrl: (value?: Partial | ((currState: T) => T)) => void; + setUrl: ( + value?: Partial | ((currState: T) => T), + options?: Options, + ) => void; }; export function useUrlState( diff --git a/packages/urlstate/react-router/useUrlState/useUrlState.ts b/packages/urlstate/react-router/useUrlState/useUrlState.ts index c751971..6bb5cb7 100644 --- a/packages/urlstate/react-router/useUrlState/useUrlState.ts +++ b/packages/urlstate/react-router/useUrlState/useUrlState.ts @@ -61,7 +61,10 @@ export function useUrlState( ): { urlState: T; setState: (value: Partial | ((currState: T) => T)) => void; - setUrl: (value?: Partial | ((currState: T) => T)) => void; + setUrl: ( + value?: Partial | ((currState: T) => T), + options?: Params, + ) => void; }; export function useUrlState( @@ -140,7 +143,7 @@ export function useUrlState( * // 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} @@ -157,7 +160,7 @@ export function useUrlState( * // 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}