From 411465582e81441e24730be7eb9e2014a8744f4d Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Thu, 13 Jul 2023 11:35:32 -0400 Subject: [PATCH] useEffect for only one hashchange listener --- src/main.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index f432b0f..3ba6709 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -16,9 +16,11 @@ const Main = (props: Props) => { const [url, setUrl] = useState(window.location.href); const hashContext = useHash(url, exhibit.stories); // Handle changes to URL - window.addEventListener("hashchange", () => { - setUrl(window.location.href); - }); + useEffect(() => { + window.addEventListener("hashchange", () => { + setUrl(window.location.href); + }); + }, []) return (