From 0190b9418bc06e9a7e2cc746096d8119623de0d5 Mon Sep 17 00:00:00 2001 From: castielwaverly <137005689+castielwaverly@users.noreply.github.com> Date: Fri, 19 Sep 2025 11:18:19 -0400 Subject: [PATCH] fix: Recalculate time ago on re-render --- 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 ff4559b5f9..969c04c43e 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; };