import { useEffect } from 'react';

export type IntervalCallback = () => void;

export const useInterval = (callback: IntervalCallback, ms: number): void => {
  useEffect(() => {
    if (ms < 0) return undefined;
    const id = window.setInterval(callback, ms);
    return () => window.clearInterval(id);
  }, [callback, ms]);
};
