A React hook that tracks scroll position and direction, updating global state for use across components.
import useOffsetTop from '@/hooks/use-offset-top'export default function Navbar() {useOffsetTop(100) // Trigger at 100px scrollreturn <nav>{/* Your navbar content */}</nav>}
top (number, optional): The scroll threshold in pixels. Defaults to 100. When scroll position exceeds this value, state.isScrolling becomes true.The hook updates the following properties in the global state object:
state.offsetTop: Current scroll position (window.scrollY)state.lastOffsetTop: Previous scroll positionstate.scrollingDirection: Current direction ('up', 'down', or 'none')state.lastScrollingDirection: Previous scroll directionstate.isScrolling: Boolean indicating if scrolled past the threshold (only when state.dialogOpen is false)isScrolling when dialog is open)The hook is used in src/components/navbar/index.tsx to manage navigation bar behavior based on scroll position.