Skip to content

Commit e3c32fb

Browse files
refactor(web): used useLocation hook instead of window object
1 parent 2793d86 commit e3c32fb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

web/src/layout/Header/DesktopHeader.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from "react";
22
import styled, { css } from "styled-components";
33

4-
import { useToggle } from "react-use";
4+
import { useLocation, useToggle } from "react-use";
55

66
import KlerosSolutionsIcon from "svgs/menu-icons/kleros-solutions.svg";
77

@@ -91,16 +91,17 @@ const DesktopHeader = () => {
9191
const [isHelpOpen, toggleIsHelpOpen] = useToggle(false);
9292
const [isSettingsOpen, toggleIsSettingsOpen] = useToggle(false);
9393
const [initialTab, setInitialTab] = useState<number>(0);
94+
const location = useLocation();
9495

9596
const initializeNotifications = () => {
96-
const hasNotifications = window.location.hash.includes("#notifications");
97-
toggleIsSettingsOpen(hasNotifications);
98-
setInitialTab(hasNotifications ? 1 : 0);
97+
const hasNotificationsPath: boolean = location.hash.includes("#notifications");
98+
toggleIsSettingsOpen(hasNotificationsPath);
99+
setInitialTab(hasNotificationsPath ? 1 : 0);
99100
};
100101

101102
useEffect(() => {
102103
initializeNotifications();
103-
}, []);
104+
}, [location.hash]);
104105

105106
useLockOverlayScroll(isDappListOpen || isHelpOpen || isSettingsOpen);
106107

web/src/pages/Home/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from "react";
22
import styled from "styled-components";
33

4-
import { useToggle } from "react-use";
4+
import { useLocation, useToggle } from "react-use";
55

66
import { HomePageProvider } from "hooks/useHomePageContext";
77
import { getOneYearAgoTimestamp } from "utils/date";
@@ -26,9 +26,11 @@ const Container = styled.div`
2626

2727
const Home: React.FC = () => {
2828
const [isOnboardingMiniGuidesOpen, toggleIsOnboardingMiniGuidesOpen] = useToggle(false);
29+
const location = useLocation();
30+
2931
useEffect(() => {
30-
toggleIsOnboardingMiniGuidesOpen(window.location.hash.includes("#onboarding"));
31-
}, []);
32+
toggleIsOnboardingMiniGuidesOpen(location.hash.includes("#onboarding"));
33+
}, [location.hash]);
3234

3335
return (
3436
<HomePageProvider timeframe={getOneYearAgoTimestamp()}>

0 commit comments

Comments
 (0)