Skip to content

Commit

Permalink
useEffect for only one hashchange listener
Browse files Browse the repository at this point in the history
  • Loading branch information
thejohnhoffer committed Jul 13, 2023
1 parent 08879e0 commit 4114655
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Index {...{
exhibit, setExhibit,
Expand Down

0 comments on commit 4114655

Please sign in to comment.