From 840069b93519116c593d502912b19f0bb5c01f29 Mon Sep 17 00:00:00 2001 From: Jesulayomy Date: Thu, 10 Jul 2025 21:53:33 -0400 Subject: [PATCH] [PageSpeed]: Implement conditional check for monitorId inside useFetchMonitorById hook --- client/src/Hooks/monitorHooks.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/client/src/Hooks/monitorHooks.js b/client/src/Hooks/monitorHooks.js index d59d88c74..b3210c1b4 100644 --- a/client/src/Hooks/monitorHooks.js +++ b/client/src/Hooks/monitorHooks.js @@ -205,18 +205,22 @@ const useFetchStatsByMonitorId = ({ const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => { const [isLoading, setIsLoading] = useState(true); useEffect(() => { - 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(); + 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 { + setIsLoading(false); + } }, [monitorId, setMonitor, updateTrigger]); return [isLoading]; };