UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

22 lines (21 loc) 900 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useOnWindowScroll = void 0; var useGlobalObjectEventListener_1 = require("./useGlobalObjectEventListener"); /** * * useOnWindowScroll hook * Fires a callback when window scroll * * @param {Function} callback Callback to be called before unmount * @param {boolean} when When the handler should be applied * @param {boolean} isLayoutEffect Should it use layout effect. Defaults to false * @see https://react-hooks.org/docs/useOnWindowScroll * */ function useOnWindowScroll(callback, when, isLayoutEffect) { if (when === void 0) { when = true; } if (isLayoutEffect === void 0) { isLayoutEffect = false; } (0, useGlobalObjectEventListener_1.useGlobalObjectEventListener)(global.window, "scroll", callback, { passive: true }, when, isLayoutEffect); } exports.useOnWindowScroll = useOnWindowScroll;