"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useOnClickOutside;
var _react = require("react");
function useOnClickOutside(_refs, handler) {
  (0, _react.useEffect)(function () {
    var listener = function listener(event) {
      var refs = Array.isArray(_refs) ? _refs : [_refs];
      if (!refs.every(function (ref) {
        return Boolean(ref.current);
      }) || refs.some(function (ref) {
        return !!ref.current && ref.current.contains(event.target);
      })) {
        return;
      }
      handler(event);
    };
    document.addEventListener('mousedown', listener);
    document.addEventListener('touchstart', listener);
    return function () {
      document.removeEventListener('mousedown', listener);
      document.removeEventListener('touchstart', listener);
    };
  }, [_refs, handler]);
}