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β
Arguments | Type | Description | Default value |
---|---|---|---|
callback | function | Callback function which needs to run on unmount | undefined |
when | boolean | When the event handler should be active | true |
A React hook for adding an event listener for window scrollβ
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.