rooks
Version:
Essential React custom hooks ⚓ to super charge your components!
19 lines (18 loc) • 733 B
JavaScript
import { useGlobalObjectEventListener } from "./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; }
useGlobalObjectEventListener(global.window, "scroll", callback, { passive: true }, when, isLayoutEffect);
}
export { useOnWindowScroll };