TeaWeb/shared/js/ui/react-elements/TimestampRenderer.tsx

18 lines
555 B
TypeScript
Raw Normal View History

2020-07-17 21:56:20 +00:00
import {useEffect, useState} from "react";
import * as React from "react";
2020-09-12 12:51:03 +00:00
import {format_chat_time} from "tc-shared/utils/DateUtils";
2020-07-17 21:56:20 +00:00
export const TimestampRenderer = (props: { timestamp: number }) => {
2020-09-12 12:51:03 +00:00
const time = format_chat_time(new Date(props.timestamp));
2020-07-17 21:56:20 +00:00
const [ revision, setRevision ] = useState(0);
useEffect(() => {
if(!time.next_update)
return;
const id = setTimeout(() => setRevision(revision + 1), time.next_update);
return () => clearTimeout(id);
});
return <>{time.result}</>;
};