React Hook: Detect Scroll Direction - Robin Wieruch

React Hook: Detect Scroll Direction - Robin Wieruch

A neat custom React Hook that I used in some of my React freelance projects which detects the scroll direction of a user:

In a function component , the custom React hook can be used this way:

That’s it. There may be many ways to improve this custom hook (e.g. check the horizontal instead of the vertical scroll direction), but for my cases it has been sufficient for now.

Recommended articles