From deaf942c0ac7035122c9902ac5e8c2dd12cac0cb Mon Sep 17 00:00:00 2001 From: shm Date: Sun, 22 Dec 2024 04:01:27 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20useHardwareData=E3=81=AE=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E5=8F=96=E5=BE=97=E3=83=AD=E3=82=B8=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useHardwareData.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hooks/useHardwareData.ts b/src/hooks/useHardwareData.ts index 7df2a7a..03d476b 100644 --- a/src/hooks/useHardwareData.ts +++ b/src/hooks/useHardwareData.ts @@ -42,7 +42,7 @@ export const useUsageUpdater = (dataType: ChartDataType) => { const getUsage = mapping[dataType].action; useEffect(() => { - const intervalId = setInterval(async () => { + const fetchAndUpdate = async () => { const result = await getUsage(); if (isResult(result) && isError(result)) return; @@ -59,7 +59,10 @@ export const useUsageUpdater = (dataType: ChartDataType) => { .concat(newHistory); return paddedHistory.slice(-chartConfig.historyLengthSec); }); - }, 1000); + }; + + fetchAndUpdate(); + const intervalId = setInterval(fetchAndUpdate, 1000); return () => clearInterval(intervalId); }, [setHistory, getUsage]);