Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

RelativeTime.tsx

9 lines472 Bytes

1import { useRelativeTimeState } from "../hooks/useRelativeTimeState";
2​
3// A "5m ago" label that keeps counting. Formatting the label inline in render
4// does not: the React Compiler caches it on the timestamp alone.
5export function RelativeTime(props: { timestamp: string }) {
6 const relative = useRelativeTimeState(props.timestamp);
7 if (relative.status !== "relative") return null;
8 return relative.suffix ? `${relative.value} ${relative.suffix}` : relative.value;
9}