import { useEffect, useRef } from 'react';
export default function useInterval(callback, delay) {
  var callbackRef = useRef();

  // update callback function with current render callback that has access to latest props and state
  useEffect(function () {
    callbackRef.current = callback;
  });
  useEffect(function () {
    if (!delay) {
      return function () {};
    }
    var interval = setInterval(function () {
      callbackRef.current && callbackRef.current();
    }, delay);
    return function () {
      return clearInterval(interval);
    };
  }, [delay]);
}