From 352d3a16479fd9d6e3f5efec2d3aaa66d6d0c7c0 Mon Sep 17 00:00:00 2001 From: Jesulayomy Date: Fri, 11 Jul 2025 13:40:29 -0400 Subject: [PATCH] [PageSpeed]: Use typeof operator for clarity, and to handle undeclared and undefined variables --- client/src/Hooks/monitorHooks.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client/src/Hooks/monitorHooks.js b/client/src/Hooks/monitorHooks.js index b3210c1b4..55c348626 100644 --- a/client/src/Hooks/monitorHooks.js +++ b/client/src/Hooks/monitorHooks.js @@ -205,22 +205,22 @@ const useFetchStatsByMonitorId = ({ const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => { const [isLoading, setIsLoading] = useState(true); useEffect(() => { - if (monitorId !== undefined) { - const fetchMonitor = async () => { - try { - setIsLoading(true); - const res = await networkService.getMonitorById({ monitorId: monitorId }); - setMonitor(res.data.data); - } catch (error) { - createToast({ body: error.message }); - } finally { - setIsLoading(false); - } - }; - fetchMonitor(); - } else { + if (typeof monitorId === "undefined") { setIsLoading(false); - } + return + }; + const fetchMonitor = async () => { + try { + setIsLoading(true); + const res = await networkService.getMonitorById({ monitorId: monitorId }); + setMonitor(res.data.data); + } catch (error) { + createToast({ body: error.message }); + } finally { + setIsLoading(false); + } + }; + fetchMonitor(); }, [monitorId, setMonitor, updateTrigger]); return [isLoading]; };