"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); function useTimeoutFn(fn, ms) { if (ms === void 0) { ms = 0; } var ready = react_1.useRef(false); var timeout = react_1.useRef(); var callback = react_1.useRef(fn); var isReady = react_1.useCallback(function () { return ready.current; }, []); var set = react_1.useCallback(function () { ready.current = false; timeout.current && clearTimeout(timeout.current); timeout.current = setTimeout(function () { ready.current = true; callback.current(); }, ms); }, [ms]); var clear = react_1.useCallback(function () { ready.current = null; timeout.current && clearTimeout(timeout.current); }, []); // update ref when function changes react_1.useEffect(function () { callback.current = fn; }, [fn]); // set on mount, clear on unmount react_1.useEffect(function () { set(); return clear; }, [ms]); return [isReady, clear, set]; } exports.default = useTimeoutFn;