import { useEffect } from 'react';
import dayjs from 'dayjs';
/**
 * Realtime 模式：每秒将当前系统时间通过 onTick 回传
 */
export function useRealtime(enabled, onTick) {
  useEffect(function () {
    if (!enabled) return;
    var id = setInterval(function () {
      onTick(dayjs());
    }, 1000);
    return function () {
      return clearInterval(id);
    };
  }, [enabled, onTick]);
}