[PageSpeed]: Use typeof operator for clarity, and to handle undeclared and undefined variables
This commit is contained in:
1 parent
f04fd8bea2
commit
352d3a1647
1 file changed
+15
-15
@@ -205,22 +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(() => {
|
||||||
if (monitorId !== undefined) {
|
if (typeof 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);
|
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]);
|
}, [monitorId, setMonitor, updateTrigger]);
|
||||||
return [isLoading];
|
return [isLoading];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user