"use strict";

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

var _throttle = require("@audentio/utils/lib/throttle");

var _react = require("react");

function useWindowResize() {
  var throttleDuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 200;

  var _useState = (0, _react.useState)({
    windowHeight: typeof window !== 'undefined' ? window.innerHeight : 0,
    windowWidth: typeof window !== 'undefined' ? window.innerWidth : 0
  }),
      state = _useState[0],
      setState = _useState[1];

  var resizeHandler = (0, _react.useCallback)((0, _throttle.throttle)(function () {
    setState({
      windowWidth: window.innerWidth,
      windowHeight: window.innerHeight
    });
  }, throttleDuration), []);
  (0, _react.useEffect)(function () {
    window.addEventListener('resize', resizeHandler);
    return function cleanup() {
      window.removeEventListener('resize', resizeHandler);
    };
  }, []);
  return state;
}
//# sourceMappingURL=useWindowResize.js.map