From e8530956faef2103ba1ead4d11ebc7b158b509fd Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Wed, 19 Feb 2025 15:06:18 +0800 Subject: [PATCH] feat: replace requestAnimationFrame with setInterval for time updates --- app/(main)/header.tsx | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/app/(main)/header.tsx b/app/(main)/header.tsx index be30659..d96ad32 100644 --- a/app/(main)/header.tsx +++ b/app/(main)/header.tsx @@ -30,32 +30,16 @@ const useCurrentTime = () => { }) useEffect(() => { - let animationFrameId: number - let lastSecond = DateTime.now().setLocale("en-US").second - - const updateTime = () => { + const intervalId = setInterval(() => { const now = DateTime.now().setLocale("en-US") - const currentSecond = now.second + setTime({ + hh: now.hour, + mm: now.minute, + ss: now.second, + }) + }, 1000) - if (currentSecond !== lastSecond) { - lastSecond = currentSecond - setTime({ - hh: now.hour, - mm: now.minute, - ss: currentSecond, - }) - } - - animationFrameId = requestAnimationFrame(updateTime) - } - - animationFrameId = requestAnimationFrame(updateTime) - - return () => { - if (animationFrameId) { - cancelAnimationFrame(animationFrameId) - } - } + return () => clearInterval(intervalId) }, []) return time