Skip to content

Commit

Permalink
Remove useEffect from TimeElapsed (#3741)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Apr 28, 2024
1 parent 256bb33 commit 361d255
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/view/com/util/TimeElapsed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ 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,
Expand All @@ -15,9 +13,11 @@ export function TimeElapsed({
const tick = useTickEveryMinute()
const [timeElapsed, setTimeAgo] = React.useState(() => ago(timestamp))

React.useEffect(() => {
const [prevTick, setPrevTick] = React.useState(tick)
if (prevTick !== tick) {
setPrevTick(tick)
setTimeAgo(ago(timestamp))
}, [timestamp, setTimeAgo, tick])
}

return children({timeElapsed})
}

0 comments on commit 361d255

Please sign in to comment.