import { useEffect } from 'react';

function useOnClickOutside(ref, handler) {
  useEffect(function () {
    var listener = function listener(event) {
      // Do nothing if clicking ref's element or descendent elements
      if (!ref.current || ref.current.contains(event.target)) {
        return;
      }

      handler(event);
    };

    if (document) {
      document.addEventListener("mousedown", listener);
      document.addEventListener("touchstart", listener);
      return function () {
        document.removeEventListener("mousedown", listener);
        document.removeEventListener("touchstart", listener);
      };
    }
  }, [ref, handler]);
}

export default useOnClickOutside;
//# sourceMappingURL=useOnClickOutside.esm.js.map
