Skip to content

Commit

Permalink
fix(use-browser-location): inline location snapshot function
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen-k committed Feb 27, 2024
1 parent dd372ac commit d7c5490
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/wouter/src/use-browser-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ const subscribeToLocationUpdates = (callback) => {
export const useLocationProperty = (fn, ssrFn) =>
useSyncExternalStore(subscribeToLocationUpdates, fn, ssrFn);

const currentSearch = () => location.search;

export const useSearch = ({ ssrSearch = "" } = {}) =>
useLocationProperty(currentSearch, () => ssrSearch);

const currentPathname = () => location.pathname;
useLocationProperty(
() => location.search,
() => ssrSearch
);

export const usePathname = ({ ssrPath } = {}) =>
useLocationProperty(
currentPathname,
ssrPath ? () => ssrPath : currentPathname
() => location.pathname,
ssrPath ? () => ssrPath : () => location.pathname
);

const currentHistoryState = () => history.state;
export const useHistoryState = () =>
useLocationProperty(currentHistoryState, () => null);
useLocationProperty(
() => history.state,
() => null
);

export const navigate = (to, { replace = false, state = null } = {}) =>
history[replace ? eventReplaceState : eventPushState](state, "", to);
Expand Down

0 comments on commit d7c5490

Please sign in to comment.