mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-01-06 04:48:14 -05:00
20 lines
582 B
TypeScript
20 lines
582 B
TypeScript
import clsx from 'clsx'
|
|
import { useEffect, useState } from 'react'
|
|
import { getCountdownString } from 'web/lib/util/time'
|
|
|
|
export function Countdown(props: { endDate: Date; className?: string }) {
|
|
const { endDate, className } = props
|
|
|
|
const [countdown, setCountdown] = useState('')
|
|
useEffect(() => {
|
|
setCountdown(getCountdownString(endDate))
|
|
|
|
const intervalId = setInterval(() => {
|
|
setCountdown(getCountdownString(endDate))
|
|
}, 1000)
|
|
return () => clearInterval(intervalId)
|
|
}, [endDate])
|
|
|
|
return <span className={clsx(className)}>{countdown}</span>
|
|
}
|