"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useScrollY = void 0;
const lodash_1 = require("lodash");
const react_1 = require("react");
// dynamically get the Y position of the window scroll
function useScrollY() {
    const [scrollY, setScrollY] = (0, react_1.useState)(0);
    // callback is important, since we want to reain the same reference
    const onScroll = (0, react_1.useCallback)((0, lodash_1.throttle)((_event) => {
        setScrollY(window.pageYOffset);
    }, 100, { trailing: true }), []);
    (0, react_1.useEffect)(() => {
        // passive: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners
        window.addEventListener("scroll", onScroll, { passive: true });
        return () => window.removeEventListener("scroll", onScroll);
    }, []);
    return scrollY;
}
exports.useScrollY = useScrollY;
//# sourceMappingURL=use-scroll-y.js.map