openpanel/packages/devtools-ui/src/components/relative-time-value.tsx
Stefan Pejcic 8595a9f4e5 back
2024-05-08 19:58:53 +02:00

24 lines
542 B
TypeScript

import React from "react";
import dayjs from "dayjs";
export const RelativeTimeValue = ({
value,
...props
}: {
value: number;
} & React.HTMLAttributes<HTMLSpanElement>) => {
const [time, setTime] = React.useState(dayjs(value).format("HH:mm:ss:SSS"));
React.useEffect(() => {
const interval = setInterval(() => {
setTime(dayjs(value).fromNow());
}, 10000);
return () => {
clearInterval(interval);
};
}, [value]);
return <span {...props}>{time}</span>;
};