From 7a2155c2710d95b7a3aa2e5f010be431832885cb Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Thu, 16 May 2019 18:40:23 +0300 Subject: [PATCH] NavBarButton active memo refactored --- src/common/NavBar/NavBarButton/NavBarButton.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/NavBar/NavBarButton/NavBarButton.js b/src/common/NavBar/NavBarButton/NavBarButton.js index f4865ab47..2564637e8 100644 --- a/src/common/NavBar/NavBarButton/NavBarButton.js +++ b/src/common/NavBar/NavBarButton/NavBarButton.js @@ -10,10 +10,12 @@ const styles = require('./styles'); const NavBarButton = React.memo(({ className, icon, label, href, onClick }) => { const locationHash = useLocationHash(); const active = React.useMemo(() => { - const locationHashPath = locationHash.startsWith('#') ? locationHash.slice(1) : ''; - const hrefHashPath = typeof href === 'string' && href.startsWith('#') ? href.slice(1) : ''; - const { pathname: locationPathname } = UrlUtils.parse(locationHashPath); - const { pathname: hrefPathname } = UrlUtils.parse(hrefHashPath); + if (typeof href !== 'string') { + return false; + } + + const { pathname: locationPathname } = UrlUtils.parse(locationHash.slice(1)); + const { pathname: hrefPathname } = UrlUtils.parse(href.slice(1)); return locationPathname === hrefPathname; }, [href, locationHash]); return (