Skip to content

Commit dd77712

Browse files
committed
Change location onChange only when it changes
1 parent 7988eab commit dd77712

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export const Context = React.createContext(
119119
export function useRouter(): [URL, SimpleLocation] {
120120
const location = React.useContext(Context);
121121
const [url, setUrl] = React.useState(location.url);
122-
React.useLayoutEffect(() => location.onChange(() => setUrl(location.url)));
122+
123+
React.useLayoutEffect(() => location.onChange(() => setUrl(location.url)), [
124+
location
125+
]);
126+
123127
return [url, location];
124128
}
125129

0 commit comments

Comments
 (0)