Remove useEffect from TimeElapsed (#3741)

zio/stable
dan 2024-04-28 22:37:00 +01:00 committed by GitHub
parent 256bb33de0
commit 361d255e95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -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,
@ -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})
}