Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix: Recalculate time ago on re-render (#4107)

castielwaverly0b15561f20ab
diff --git a/packages/common/src/hooks.ts b/packages/common/src/hooks.ts
index ff4559b5f..969c04c43 100644
--- a/packages/common/src/hooks.ts
+++ b/packages/common/src/hooks.ts
@@ -11,13 +11,17 @@ const calculateTimeAgo = (timestamp: Date) => {
};
export const useTimeAgo = (timestamp: Date, updateFrequency = 1000) => {
- const [timeAgo, setTimeAgo] = useState(calculateTimeAgo(timestamp));
+ const [timeAgo, setTimeAgo] = useState(() => calculateTimeAgo(timestamp));
+
+ useEffect(() => {
+ setTimeAgo(calculateTimeAgo(timestamp));
+ }, [timestamp]);
useEffect(() => {
const intervalId = setInterval(() => setTimeAgo(calculateTimeAgo(timestamp)), updateFrequency);
return () => clearInterval(intervalId); // clear interval on hook unmount
- }, [timestamp]);
+ }, [timestamp, updateFrequency]);
return timeAgo;
};