From d7c5490ea19fd20b6651a5dd51f075561a9c2385 Mon Sep 17 00:00:00 2001 From: junwen-k <40173716+junwen-k@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:26:00 +0800 Subject: [PATCH] fix(use-browser-location): inline location snapshot function --- packages/wouter/src/use-browser-location.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/wouter/src/use-browser-location.js b/packages/wouter/src/use-browser-location.js index 22ffb8ec..4c650cf6 100644 --- a/packages/wouter/src/use-browser-location.js +++ b/packages/wouter/src/use-browser-location.js @@ -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);