From 5c74c0e452b96b199a52383ebd11c14a928187a4 Mon Sep 17 00:00:00 2001 From: Vishnu Sreekumaran Nair <200557136@student.georgianc.on.ca> Date: Tue, 18 Mar 2025 12:18:52 -0400 Subject: [PATCH] removed conditional calling of hook and added early return in useHardwareMonitorsFetch --- src/Pages/Infrastructure/Create/index.jsx | 2 +- .../Details/Hooks/useHardwareMonitorsFetch.jsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Pages/Infrastructure/Create/index.jsx b/src/Pages/Infrastructure/Create/index.jsx index 6857be61e..be45439dc 100644 --- a/src/Pages/Infrastructure/Create/index.jsx +++ b/src/Pages/Infrastructure/Create/index.jsx @@ -61,7 +61,7 @@ const CreateInfrastructureMonitor = () => { const isCreate = typeof monitorId === "undefined"; // Fetch monitor details if editing - const { monitor, isLoading, networkError } = isCreate ? {} : useHardwareMonitorsFetch({ monitorId }); + const { monitor, isLoading, networkError } = useHardwareMonitorsFetch({ monitorId }); // State const [errors, setErrors] = useState({}); diff --git a/src/Pages/Infrastructure/Details/Hooks/useHardwareMonitorsFetch.jsx b/src/Pages/Infrastructure/Details/Hooks/useHardwareMonitorsFetch.jsx index a5b84cfa4..229561966 100644 --- a/src/Pages/Infrastructure/Details/Hooks/useHardwareMonitorsFetch.jsx +++ b/src/Pages/Infrastructure/Details/Hooks/useHardwareMonitorsFetch.jsx @@ -2,6 +2,11 @@ import { useEffect, useState } from "react"; import { networkService } from "../../../../main"; const useHardwareMonitorsFetch = ({ monitorId, dateRange }) => { + + // Abort early if creating monitor + if (!monitorId) { + return { monitor: null, isLoading: false, networkError: null }; + } const [isLoading, setIsLoading] = useState(true); const [networkError, setNetworkError] = useState(false); const [monitor, setMonitor] = useState(undefined);