Skip to content

Commit

Permalink
fix: setState in 'reset'
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Jan 30, 2025
1 parent 5021922 commit b376aa3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/urlstate/useUrlStateBase/useUrlStateBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export function useUrlStateBase<T extends JSONCompatible>(
...value,
};

setState(newVal);

const qStr = stringify(newVal, getOtherParams(defaultState));

const newUrl = `${window.location.pathname}${qStr.length ? "?" : ""}${qStr}${window.location.hash}`;
const currUrl = `${window.location.pathname}${window.location.search}${window.location.hash}`;
if (newUrl === currUrl) return;

setState(newVal);

const { replace, ..._rest } = options || {};
queue.current.push([replace ? "replace" : "push", newUrl, _rest]);

Expand All @@ -122,6 +122,7 @@ export function useUrlStateBase<T extends JSONCompatible>(

const reset = React.useCallback(
(options?: Options) => {
setState(defaultState);
updateUrl(defaultState, options);
},
[updateUrl, setState],
Expand Down

0 comments on commit b376aa3

Please sign in to comment.