[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 [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];
};