How to Get Window Scroll Position in React js
Hello devs,
In this tutorial i will show you how to get react window scroll position. To get this window scroll position, i will use react hook like @rehooks/window-scroll-position
. It is very simple package to get window scroll position.
This react scroll position hook tutorial, you will get how to get react get scroll position very easily. If you don't know how to get scroll position then this tutorial is for you. Let's see the example code:
FIrst we need to install this package. So run below command to install it.
yarn add @rehooks/window-scroll-position
//or
npm i @rehooks/window-scroll-position
And now use this hook like that
src/App.js
Now if you scroll, you will get the scroll position like that:
{x: 0, y: 0}
{x: 0, y: 1}
{x: 0, y: 44}
{x: 0, y: 179}
{x: 0, y: 212}
{x: 0, y: 213}
{x: 0, y: 254}
Hope it can help you.