"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRafThrottle = useRafThrottle;
const react_1 = require("react");
const react_use_1 = require("react-use");
function useRafThrottle(fn) {
    const refFn = (0, react_use_1.useLatest)(fn);
    const refHandle = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        return () => {
            if (refHandle.current !== null) {
                cancelAnimationFrame(refHandle.current);
            }
        };
    }, [refFn]);
    return (0, react_1.useCallback)(() => {
        if (refHandle.current === null) {
            refHandle.current = requestAnimationFrame(() => {
                refHandle.current = null;
                refFn.current();
            });
        }
    }, [refFn]);
}
//# sourceMappingURL=use-raf-throttle.js.map
