Skip to content

useScrollDirection

@hua-labs/hua/framework
Pro

bash
npm install @hua-labs/hua
tsx
import { useScrollDirection } from "@hua-labs/hua/framework";

tsx
import { useScrollDirection } from "@hua-labs/hua/framework";

const { direction, scrollY, isScrollingUp, isScrollingDown } = useScrollDirection({
  threshold: 10, // Minimum scroll delta
  throttle: 100, // Throttle in ms
});

return (
  <header className={isScrollingDown ? 'hidden' : 'visible'}>
    {/* Header hides on scroll down, shows on scroll up */}
  </header>
);

0px

none

Smart Header

1

2

3

4

5

6

7

8

9

10

thresholdnumber10
throttlenumber100
targetRefRefObjectwindow
initialDirection"up" | "down" | "none""none"

direction"up" | "down" | "none"
scrollYnumber
isScrollingUpboolean
isScrollingDownboolean
deltanumber
progressnumber
mountedboolean