react-scroll-position returns the browser viewport X and Y scroll position. It is highly optimized 🚀 using the special techniques to avoid unnecessary rerenders!
npm install rscroll-position>


``bash`
npm install --save rscroll-position
| Prop | Description |
| :--- |:--- |
| element | reference to DOM element/node |
| delay | The delay (to throttle events) in ms. |
| useWindow | Use window.scroll if true otherwise document.body.getBoundingClientRect() to detect scroll position. |
| deps | Dependency array |
`js
import { useState, useRef } from 'react';
import { useScrollPosition } from 'rscroll-position';
function App(){
const [ trackPosition, setTrackPosition ] = useScrollPosition (false);
// refference to DOM element
const element = useRef();
useScrollPosition(({previous, current})=> {
console.log({previous, current})
},
element, // element
true, // useWindow
700, // delay ms
[trackPosition] // deps
);
return (
MIT © Chitova263