npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@n0n3br/react-use-scroll-direction

v0.1.3

Published

A robust React hook to detect vertical scroll direction ('up', 'down', 'static') for any DOM element or the window.

Downloads

7

Readme

@n0n3br/react-use-scroll-direction

npm version

A robust React hook to detect vertical scroll direction ('up', 'down', 'static') for any DOM element or the window.

Installation

Using pnpm:

pnpm add @n0n3br/react-use-scroll-direction

Using npm:

npm install @n0n3br/react-use-scroll-direction

Using yarn:

yarn add @n0n3br/react-use-scroll-direction

Usage

Basic Window Scroll

import React from "react";
import { useScrollDirection } from "@n0n3br/react-use-scroll-direction";

const App = () => {
  const scrollDirection = useScrollDirection();

  return (
    <div style={{ height: "200vh", padding: "20px" }}>
      <p>Scroll direction: {scrollDirection}</p>
      <p>Scroll down or up to see the direction change.</p>
    </div>
  );
};

export default App;

Element Specific Scroll

import React, { useRef } from "react";
import { useScrollDirection } from "@n0n3br/react-use-scroll-direction";

const App = () => {
  const scrollableRef = useRef<HTMLDivElement | null>(null);
  const scrollDirection = useScrollDirection(scrollableRef);

  return (
    <div style={{ padding: "20px" }}>
      <p>Scroll direction for the div: {scrollDirection}</p>
      <div
        ref={scrollableRef}
        style={{
          height: "300px",
          overflowY: "scroll",
          border: "1px solid black",
        }}
      >
        <div style={{ height: "600px", padding: "10px" }}>
          <p>Scrollable content inside the div.</p>
          <p>Scroll me!</p>
        </div>
      </div>
    </div>
  );
};

export default App;

With Options

import React, { useRef } from "react";
import { useScrollDirection } from "@n0n3br/react-use-scroll-direction";

const App = () => {
  const scrollableRef = useRef<HTMLDivElement | null>(null);
  const scrollDirection = useScrollDirection(scrollableRef, {
    threshold: 30, // Pixels to scroll before direction changes
    throttleDelay: 150, // Milliseconds to throttle scroll events (uses setTimeout if > 0 and not 100, otherwise requestAnimationFrame)
  });

  // ... rest of your component
  return (
    <div>
      {/* Your component JSX using scrollDirection */}
      <p>Scroll direction: {scrollDirection}</p>
    </div>
  );
};

export default App;

API

useScrollDirection(ref?, options?)

Parameters:

  • ref (optional): React.RefObject<HTMLElement | null>
    • A React ref object pointing to the DOM element for which to track scroll direction.
    • If not provided, the hook defaults to tracking the window scroll.
  • options (optional): UseScrollDirectionOptions
    • An object to configure the hook's behavior.
    • threshold (optional): number
      • The minimum number of pixels the user must scroll before the direction is updated.
      • Default: 0
    • throttleDelay (optional): number
      • The delay in milliseconds to throttle scroll event handling.
      • Uses requestAnimationFrame for optimal performance by default (when throttleDelay is 100 or not specified).
      • If a throttleDelay other than 100 (and greater than 0) is provided, setTimeout will be used for throttling with that specific delay.
      • Set to 0 to disable throttling (not recommended for performance-sensitive applications).
      • Default: 100 (uses requestAnimationFrame)

Return Value:

  • ScrollDirection: 'up' | 'down' | 'static'
    • The current detected vertical scroll direction.

Types:

export type ScrollDirection = "up" | "down" | "static";

export interface UseScrollDirectionOptions {
  threshold?: number;
  throttleDelay?: number;
}

Live Example

Example app

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

MIT