blob: 02b0f2314b6997fe271b917faa4c70f9c44cca29 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import React from 'react'
import {useTickEveryMinute} from '#/state/shell'
import {ago} from 'lib/strings/time'
export function TimeElapsed({
timestamp,
children,
}: {
timestamp: string
children: ({timeElapsed}: {timeElapsed: string}) => JSX.Element
}) {
const tick = useTickEveryMinute()
const [timeElapsed, setTimeAgo] = React.useState(() => ago(timestamp))
const [prevTick, setPrevTick] = React.useState(tick)
if (prevTick !== tick) {
setPrevTick(tick)
setTimeAgo(ago(timestamp))
}
return children({timeElapsed})
}
|