"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var react_1 = require("react"); var useEvent_1 = tslib_1.__importDefault(require("./useEvent")); var util_1 = require("./misc/util"); var createKeyPredicate = function (keyFilter) { return typeof keyFilter === 'function' ? keyFilter : typeof keyFilter === 'string' ? function (event) { return event.key === keyFilter; } : keyFilter ? function () { return true; } : function () { return false; }; }; var useKey = function (key, fn, opts, deps) { if (fn === void 0) { fn = util_1.noop; } if (opts === void 0) { opts = {}; } if (deps === void 0) { deps = [key]; } var _a = opts.event, event = _a === void 0 ? 'keydown' : _a, target = opts.target, options = opts.options; var useMemoHandler = react_1.useMemo(function () { var predicate = createKeyPredicate(key); var handler = function (handlerEvent) { if (predicate(handlerEvent)) { return fn(handlerEvent); } }; return handler; }, deps); useEvent_1.default(event, useMemoHandler, target, options); }; exports.default = useKey;