Skip to main content
Version: Next

useOnWindowScroll

About​

A React hook for adding an event listener for window scroll


Installation​

npm install --save rooks

Importing the hook​

import { useOnWindowScroll } from "rooks";

Usage​

function Demo() {
useOnWindowScroll(() => console.log("window scrolled"));
return <p> Hello world </p>;
}

render(<Demo />);

Arguments​

ArgumentsTypeDescriptionDefault value
callbackfunctionCallback function which needs to run on unmountundefined
whenbooleanWhen the event handler should be activetrue
isLayoutEffectbooleanShould it use layout effect.false

Returns​

No return value.

Codesandbox Example​

Basic Usage​

Join Bhargav's discord server​

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.