Files
llink/js/desktop/src/components/relative-timestamp.tsx
T
Arjun PatelandGitHub a8a0b7db1b infra: add linting and formatting for js projects (#230)
* wip

* wip

* wip

* format

* wip(mobile): lint and format

* cleanup

* nits

* nits

* idiomatic react

* nit

* format all root files
2026-06-02 07:44:24 -07:00

23 lines
565 B
TypeScript

import { useEffect, useState } from 'react';
import { formatDistanceToNow } from '@/lib/time-utils';
const TICK_MS = 30_000;
interface RelativeTimestampProps {
date: Date;
}
/**
* Displays a relative timestamp (e.g. "5m ago") that auto-refreshes every 30s.
*/
export function RelativeTimestamp({ date }: RelativeTimestampProps) {
const [, setTick] = useState(0);
useEffect(() => {
const id = setInterval(() => setTick((t) => t + 1), TICK_MS);
return () => clearInterval(id);
}, []);
return <>{formatDistanceToNow(date.toISOString())}</>;
}