'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');

function useDisableScroll(ref) {
  var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  React.useEffect(function () {
    if (!enabled || !ref.current) return;
    var el = ref.current;
    var preventScroll = function preventScroll(e) {
      e.preventDefault();
      e.stopPropagation();
    };
    el.addEventListener('wheel', preventScroll, {
      passive: false
    });
    el.addEventListener('touchmove', preventScroll, {
      passive: false
    });
    return function () {
      el.removeEventListener('wheel', preventScroll);
      el.removeEventListener('touchmove', preventScroll);
    };
  }, [ref, enabled]);
}

exports.useDisableScroll = useDisableScroll;
