Skip to content

Commit

Permalink
Merge pull request #39 from shm11C3/fix/usageUpdater
Browse files Browse the repository at this point in the history
使用率の取得タイミングが1秒遅れている問題の修正
  • Loading branch information
shm11C3 authored Dec 21, 2024
2 parents f541faa + deaf942 commit 174e0bb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useHardwareData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand Down

0 comments on commit 174e0bb

Please sign in to comment.