@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com's products.
13 lines (12 loc) • 385 B
JavaScript
import useEventListener from "../useEventListener";
const useClickOutside = (ref, handler, mouseEvent = "mousedown") => {
useEventListener(mouseEvent, event => {
const el = ref?.current;
// Do nothing if clicking ref's element or descendent elements
if (!el || el.contains(event.target)) {
return;
}
handler(event);
});
};
export default useClickOutside;