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