"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = require("react");

/**
 *  useInterval is a custom hook to get useEffect and intervals to work together
 *
 * When trying to implement setInterval in a useEffect that happens onMount, the effect would only have the value of a prop or state variable on first render
 * This custom hook is to ensure that the callback of setInterval receives updated props
 * @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
 * */
function useInterval(callback, delay) {
  var savedCallback = (0, _react.useRef)(); // Remember the latest callback.

  (0, _react.useEffect)(function () {
    savedCallback.current = callback;
  }, [callback]); // Set up the interval.

  (0, _react.useEffect)(function () {
    function tick() {
      savedCallback.current();
    }

    if (delay !== null) {
      var id = setInterval(tick, delay);
      return function () {
        return clearInterval(id);
      };
    }
  }, [delay]);
}

var _default = useInterval;
exports.default = _default;