A react hook to use scroll position
npm install react-use-scroll-position 
A react hook to use scroll position.
``tsx
import React from 'react';
// Usually you would just need to import one of the following
import { useScrollPosition, useScrollXPosition, useScrollYPosition } from 'react-use-scroll-position';
function Example() {
const { x, y } = useScrollPosition();
const scrollX = useScrollXPosition();
const scrollY = useScrollYPosition();
return (
<>
{x} should equal to {scrollX}.
{y} should equal to {scrollY}.
$3
`tsx
import { useScrollPosition } from 'react-use-scroll-position';function useYourImagination() {
const { x, y } = useScrollPosition();
return getSomethingAwesomeWith(x, y);
}
`Implementation details
The scroll event handler is throttled by
requestAnimationFrame`.