about summary refs log tree commit diff
path: root/src/view/com/util/TimeElapsed.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/util/TimeElapsed.tsx')
-rw-r--r--src/view/com/util/TimeElapsed.tsx16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/view/com/util/TimeElapsed.tsx b/src/view/com/util/TimeElapsed.tsx
index 6ea41b82b..a5d3a5372 100644
--- a/src/view/com/util/TimeElapsed.tsx
+++ b/src/view/com/util/TimeElapsed.tsx
@@ -3,21 +3,25 @@ import React from 'react'
 import {useTickEveryMinute} from '#/state/shell'
 import {ago} from 'lib/strings/time'
 
-// FIXME(dan): Figure out why the false positives
-
 export function TimeElapsed({
   timestamp,
   children,
+  timeToString = ago,
 }: {
   timestamp: string
   children: ({timeElapsed}: {timeElapsed: string}) => JSX.Element
+  timeToString?: (timeElapsed: string) => string
 }) {
   const tick = useTickEveryMinute()
-  const [timeElapsed, setTimeAgo] = React.useState(() => ago(timestamp))
+  const [timeElapsed, setTimeAgo] = React.useState(() =>
+    timeToString(timestamp),
+  )
 
-  React.useEffect(() => {
-    setTimeAgo(ago(timestamp))
-  }, [timestamp, setTimeAgo, tick])
+  const [prevTick, setPrevTick] = React.useState(tick)
+  if (prevTick !== tick) {
+    setPrevTick(tick)
+    setTimeAgo(timeToString(timestamp))
+  }
 
   return children({timeElapsed})
 }