TimeToNow.tsx 484 B

12345678910111213141516
  1. import React, { FC, useEffect, useState } from 'react';
  2. import { dateTimeFormatTimeAgo, DateTimeInput } from '@grafana/data';
  3. export interface Props {
  4. date: DateTimeInput;
  5. }
  6. export const TimeToNow: FC<Props> = ({ date }) => {
  7. const setRandom = useState(0)[1];
  8. useEffect(() => {
  9. const interval = setInterval(() => setRandom(Math.random()), 1000);
  10. return () => clearInterval(interval);
  11. });
  12. return <span title={String(date)}>{dateTimeFormatTimeAgo(date)}</span>;
  13. };