From 0b15561f20abe94908ee62f99a33ff3f030c49e2 Mon Sep 17 00:00:00 2001 From: castielwaverly <137005689+castielwaverly@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:30:56 -0400 Subject: [PATCH] fix: Recalculate time ago on re-render (#4107) --- packages/common/src/hooks.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; };