2026-01-08 16:43:14 +01:00
|
|
|
import { useState, useEffect } from 'react';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the current time in seconds, updating periodically.
|
|
|
|
|
* This prevents unnecessary rerenders by only updating every 60 seconds
|
|
|
|
|
* instead of on every render cycle.
|
|
|
|
|
*
|
|
|
|
|
* For visual updates like blinking animations, CSS handles that independently.
|
|
|
|
|
* This hook is for time-based calculations that don't need millisecond precision.
|
|
|
|
|
*/
|
|
|
|
|
export const useCurrentTime = (updateIntervalSeconds = 60) => {
|
|
|
|
|
const [currentTime, setCurrentTime] = useState(() => Date.now() / 1000);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-01-08 17:16:29 +01:00
|
|
|
// Update periodically
|
2026-01-08 16:43:14 +01:00
|
|
|
const intervalId = setInterval(() => {
|
|
|
|
|
setCurrentTime(Date.now() / 1000);
|
|
|
|
|
}, updateIntervalSeconds * 1000);
|
|
|
|
|
|
|
|
|
|
return () => clearInterval(intervalId);
|
|
|
|
|
}, [updateIntervalSeconds]);
|
|
|
|
|
|
|
|
|
|
return currentTime;
|
|
|
|
|
};
|