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

@eightmay/use-infinite-scroll

v1.0.2

Published

Lightweight React infinite scroll hook

Downloads

24

Readme

📦 @eightmay/use-infinite-scroll

A lightweight and dependency-free React infinite scroll hook that triggers a callback when the user scrolls near the bottom of a container. Ideal for feeds, timelines, infinite lists, dashboards, and lazy-loaded content.


🌟 Features

  • Zero Dependencies: Extremely lightweight.
  • Container-Based: Works with any scrollable container.
  • Built-In Lock: Prevents multiple triggers.
  • Promise-Friendly: Supports async loaders.
  • TypeScript Support: Fully typed API.
  • Simple API: Easy to integrate.

🚀 Installation

Install the package using your preferred package manager:

# Using npm
npm install @eightmay/use-infinite-scroll

# Using yarn
yarn add @eightmay/use-infinite-scroll

# Using pnpm
pnpm add @eightmay/use-infinite-scroll

📘 Usage Example

Here’s how to use useInfiniteScroll in a React component:

import { useRef } from "react";
import { useInfiniteScroll } from "@eightmay/use-infinite-scroll";

export default function Feed() {
  const scrollRef = useRef(null);

  const loadMore = async () => {
    // Fetch the next page or more items
    console.log("Loading more items...");
  };

  useInfiniteScroll({
    scrollRef,
    threshold: 80, // Trigger when 80px from the bottom
    onReach: loadMore,
  });

  return (
    <div ref={scrollRef} className="overflow-y-scroll h-[600px] border rounded">
      {/* Render feed items here */}
      <p>Item 1</p>
      <p>Item 2</p>
      <p>Item 3</p>
    </div>
  );
}

⚙️ API Reference

useInfiniteScroll(options)

| Option | Type | Default | Description | | ----------- | ------------------------------ | ------------ | ------------------------------------------------------------- | | scrollRef | React.RefObject<HTMLElement> | Required | Reference to the scrollable container. | | threshold | number | 80 | Distance (in pixels) from the bottom to trigger the callback. | | onReach | () => Promise<void> \| void | Required | Callback fired when the bottom is reached. |


🛠️ Example with Async Loader

import { useInfiniteScroll } from "@eightmay/use-infinite-scroll"
import { useRef, useState } from "react"

export default function InfiniteFeed() {
  const scrollRef = useRef(null)
  const [items, setItems] = useState(Array.from({ length: 20 }, (_, i) => `Item ${i + 1}`))
  const [isLoading, setIsLoading] = useState(false)

  const loadMore = async () => {
    if (isLoading) return
    setIsLoading(true)

    // Simulate an API call
    await new Promise((resolve) => setTimeout(resolve, 1000))
    setItems((prev) => [
      ...prev,
      ...Array.from({ length: 10 }, (_, i) => `Item ${prev.length + i + 1}`),
    ])

    setIsLoading(false)
  }

  useInfiniteScroll({
    scrollRef,
    threshold: 100,
    onReach: loadMore,
  })

  return (
    <div
      ref={scrollRef}
      className="h-full w-full overflow-y-scroll rounded-xl border-1 border-gray-700 p-4"
    >
      {items.map((item, index) => (
        <p key={index}>{item}</p>
      ))}
      {isLoading && <p>Loading more...</p>}
    </div>
  )
}

📖 Notes

  • Scroll Container: Ensure the scrollRef points to a scrollable container with overflow-y: scroll.
  • Threshold: Adjust the threshold value based on your UI requirements.
  • Lock Mechanism: The hook prevents multiple triggers while the onReach callback is running.

🏁 License

MIT © Eightmay