import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import * as React from 'react';
export function useTimeout(callback, delay) {
  var timeoutRef = React.useRef(undefined);
  var savedCallback = React.useRef(callback);

  var _React$useReducer = React.useReducer(function (x) {
    return x + 1;
  }, 0),
      _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
      update = _React$useReducer2[0],
      restart = _React$useReducer2[1];

  React.useEffect(function () {
    savedCallback.current = callback;
  }, [callback]);
  React.useEffect(function () {
    var tick = function tick() {
      return savedCallback.current();
    };

    if (typeof delay === 'number') {
      timeoutRef.current = window.setTimeout(tick, delay);
      return function () {
        return window.clearTimeout(timeoutRef.current);
      };
    }
  }, [delay, update]);
  return restart;
}