21 lines
523 B
TypeScript
Raw Normal View History

2019-11-11 10:40:05 +02:00
import React from 'react';
import { FormattedRelativeTime } from 'react-intl';
import { selectUnit } from '@formatjs/intl-utils';
function RelativeTime({ timestamp }: { timestamp: number }) {
2019-12-07 13:28:52 +02:00
const { unit, value }: { unit: any; value: number } = selectUnit(timestamp);
2019-11-11 10:40:05 +02:00
return (
<FormattedRelativeTime
value={value}
unit={unit}
numeric="auto"
updateIntervalInSeconds={
['seconds', 'minute', 'hour'].includes(unit) ? 1 : undefined
}
/>
);
2019-11-11 10:40:05 +02:00
}
export default RelativeTime;