A react hook to use scroll position.
importReactfrom'react';// Usually you would just need to import one of the followingimport{useScrollPosition,useScrollXPosition,useScrollYPosition}from'react-use-scroll-position';functionExample(){const{ x, y }=useScrollPosition();constscrollX=useScrollXPosition();constscrollY=useScrollYPosition();return(<><p>{x} should equal to {scrollX}.
</p><p>{y} should equal to {scrollY}.
</p></>);}import{useScrollPosition}from'react-use-scroll-position';functionuseYourImagination(){const{ x, y }=useScrollPosition();returngetSomethingAwesomeWith(x,y);}The scroll event handler is throttled by requestAnimationFrame.