mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
feat: replace requestAnimationFrame with setInterval for time updates
This commit is contained in:
parent
4171829a15
commit
e8530956fa
@ -30,32 +30,16 @@ const useCurrentTime = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let animationFrameId: number
|
const intervalId = setInterval(() => {
|
||||||
let lastSecond = DateTime.now().setLocale("en-US").second
|
|
||||||
|
|
||||||
const updateTime = () => {
|
|
||||||
const now = DateTime.now().setLocale("en-US")
|
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) {
|
return () => clearInterval(intervalId)
|
||||||
lastSecond = currentSecond
|
|
||||||
setTime({
|
|
||||||
hh: now.hour,
|
|
||||||
mm: now.minute,
|
|
||||||
ss: currentSecond,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
animationFrameId = requestAnimationFrame(updateTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
animationFrameId = requestAnimationFrame(updateTime)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (animationFrameId) {
|
|
||||||
cancelAnimationFrame(animationFrameId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return time
|
return time
|
||||||
|
Loading…
Reference in New Issue
Block a user