(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = require("react");
    var useDebounce = function (func, wait) {
        if (wait === void 0) { wait = 0; }
        var timeoutRef = (0, react_1.useRef)(null);
        (0, react_1.useEffect)(function () { return function () {
            timeoutRef.current && clearTimeout(timeoutRef.current);
        }; }, [wait]);
        return (0, react_1.useCallback)(function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            if (timeoutRef.current) {
                clearTimeout(timeoutRef.current);
            }
            timeoutRef.current = setTimeout(function () {
                timeoutRef.current = null;
                if (typeof func === "function") {
                    func.apply(void 0, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(args), false));
                }
            }, wait);
        }, [wait, func]);
    };
    exports.default = useDebounce;
});
