mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
24 lines
542 B
TypeScript
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>;
|
|
};
|