@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.
28 lines (23 loc) • 745 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var useClickOutside = function useClickOutside(ref, handler) {
(0, _react.useEffect)(function () {
var handleClose = function handleClose(event) {
if (ref.current && !ref.current.contains(event.target)) {
handler(event);
}
};
window.addEventListener("mousedown", handleClose);
window.addEventListener("touchstart", handleClose);
return function () {
window.removeEventListener("mousedown", handleClose);
window.removeEventListener("touchstart", handleClose);
};
}, [handler, ref]);
};
var _default = useClickOutside;
exports.default = _default;