[PageSpeed]: Implement conditional check for monitorId inside useFetchMonitorById hook

This commit is contained in:
Jesulayomy committed 2025-07-10 21:53:33 -04:00
1 parent eaa85bb9c4
commit 840069b935
1 file changed
+16 -12
+16 -12
View File
@@ -205,18 +205,22 @@ const useFetchStatsByMonitorId = ({
const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => { const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => { if (monitorId !== undefined) {
try { const fetchMonitor = async () => {
setIsLoading(true); try {
const res = await networkService.getMonitorById({ monitorId: monitorId }); setIsLoading(true);
setMonitor(res.data.data); const res = await networkService.getMonitorById({ monitorId: monitorId });
} catch (error) { setMonitor(res.data.data);
createToast({ body: error.message }); } catch (error) {
} finally { createToast({ body: error.message });
setIsLoading(false); } finally {
} setIsLoading(false);
}; }
fetchMonitor(); };
fetchMonitor();
} else {
setIsLoading(false);
}
}, [monitorId, setMonitor, updateTrigger]); }, [monitorId, setMonitor, updateTrigger]);
return [isLoading]; return [isLoading];
}; };