feat: replace requestAnimationFrame with setInterval for time updates

This commit is contained in:
hamster1963 2025-02-19 15:06:18 +08:00
parent 4171829a15
commit e8530956fa

View File

@ -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
if (currentSecond !== lastSecond) {
lastSecond = currentSecond
setTime({
hh: now.hour,
mm: now.minute,
ss: currentSecond,
ss: now.second,
})
}
}, 1000)
animationFrameId = requestAnimationFrame(updateTime)
}
animationFrameId = requestAnimationFrame(updateTime)
return () => {
if (animationFrameId) {
cancelAnimationFrame(animationFrameId)
}
}
return () => clearInterval(intervalId)
}, [])
return time