"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); var util_1 = require("./misc/util"); var defaultEvents = ['mousedown', 'touchstart']; var useClickAway = function (ref, onClickAway, events) { if (events === void 0) { events = defaultEvents; } var savedCallback = react_1.useRef(onClickAway); react_1.useEffect(function () { savedCallback.current = onClickAway; }, [onClickAway]); react_1.useEffect(function () { var handler = function (event) { var el = ref.current; el && !el.contains(event.target) && savedCallback.current(event); }; for (var _i = 0, events_1 = events; _i < events_1.length; _i++) { var eventName = events_1[_i]; util_1.on(document, eventName, handler); } return function () { for (var _i = 0, events_2 = events; _i < events_2.length; _i++) { var eventName = events_2[_i]; util_1.off(document, eventName, handler); } }; }, [events, ref]); }; exports.default = useClickAway;