Last active
August 14, 2024 13:21
-
-
Save shobhit-jain/76e539c0ca0109e5137ebe5697624944 to your computer and use it in GitHub Desktop.
Next.js - Detecting Scrolling Direction - Up / Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { useScrollDirection } from 'react-use-scroll-direction' | |
export const Window_Scroll_Direction = () => { | |
const [direction, setDirection] = React.useState(String) | |
const { isScrollingUp, isScrollingDown } = useScrollDirection() | |
React.useEffect(() => { | |
isScrollingDown && setDirection('down') | |
isScrollingUp && setDirection('up') | |
}, [isScrollingDown, isScrollingUp]) | |
return ( | |
<> | |
<div className="fixed top-0 bg-white"> | |
{direction === 'down' ? 'Scrolling down' : 'scrolling up'} | |
</div> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment