import useEventListener from "../hooks/useEventListener";

function useOnClickOutside(ref, handler) {
  var mouseEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "mousedown";
  useEventListener(mouseEvent, function (event) {
    var el = ref === null || ref === void 0 ? void 0 : ref.current; // Do nothing if clicking ref's element or descendent elements

    if (!el || el.contains(event.target)) {
      return;
    }

    handler(event);
  });
}

export default useOnClickOutside;