From 56bc5b083625a7d33bcab0343b5cb31d774d4407 Mon Sep 17 00:00:00 2001 From: Goulin Khoge <36013798+goulinkh@users.noreply.github.com> Date: Fri, 17 Mar 2023 17:04:41 +0100 Subject: [PATCH] Update PrimaryNav.tsx --- src/components/PrimaryNav/PrimaryNav.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/PrimaryNav/PrimaryNav.tsx b/src/components/PrimaryNav/PrimaryNav.tsx index 5721a897f..713f7259d 100644 --- a/src/components/PrimaryNav/PrimaryNav.tsx +++ b/src/components/PrimaryNav/PrimaryNav.tsx @@ -3,7 +3,7 @@ import { Icon, StatusLabel, Tooltip } from "@canonical/react-components"; import classNames from "classnames"; import Logo from "components/Logo/Logo"; import UserMenu from "components/UserMenu/UserMenu"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useSelector } from "react-redux"; import { NavLink } from "react-router-dom"; import { getAppVersion } from "store/general/selectors"; @@ -70,20 +70,18 @@ const ControllersLink = () => { ); }; -let didInit = false; const PrimaryNav = () => { const appVersion = useSelector(getAppVersion); const [updateAvailable, setUpdateAvailable] = useState(false); + let versionRequested = useRef(false); useEffect(() => { - if (didInit || !appVersion) return; - didInit = true; - dashboardUpdateAvailable(appVersion || "").then((e) => { - setUpdateAvailable(e); - }); - return () => { - didInit = false; - }; + if (appVersion && !versionRequested.current) { + dashboardUpdateAvailable(appVersion || "").then((e) => { + setUpdateAvailable(e); + }); + versionRequested.current = true; + } }, [appVersion]); return (