import { useEffect } from 'react';
export default function useOnClickOutside(_refs, handler) {
  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]);
}