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

react-scroll-infinity

v1.0.1

Published

A performant React hook for infinite scrolling using Intersection Observer API

Readme

react-scroll-infinity

A performant React hook for infinite scrolling using the Intersection Observer API.

Created by Sayed Abdul Karim

npm version license

🚀 Live Demo | 🎮 Playground

Features

  • Performant - Uses Intersection Observer (no scroll event listeners)
  • Lightweight - ~1KB minified
  • TypeScript - Full type support
  • Configurable - Customize threshold and root margin
  • Zero dependencies - Only requires React as peer dependency

Installation

npm install react-scroll-infinity
yarn add react-scroll-infinity
pnpm add react-scroll-infinity

Usage

import { useInfiniteScroll } from 'react-scroll-infinity';

function PostList() {
  const [posts, setPosts] = useState([]);
  const [page, setPage] = useState(1);
  const [hasMore, setHasMore] = useState(true);

  const loadMore = async () => {
    const newPosts = await fetchPosts(page);
    setPosts(prev => [...prev, ...newPosts]);
    setHasMore(newPosts.length > 0);
    setPage(prev => prev + 1);
  };

  const { sentinelRef, isLoading, error } = useInfiniteScroll({
    loadMore,
    hasMore,
  });

  return (
    <div>
      {posts.map(post => (
        <PostCard key={post.id} post={post} />
      ))}

      {/* Sentinel element - triggers loading when visible */}
      <div ref={sentinelRef}>
        {isLoading && <span>Loading...</span>}
        {error && <span>Error: {error.message}</span>}
        {!hasMore && <span>No more posts</span>}
      </div>
    </div>
  );
}

API

useInfiniteScroll(options)

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | loadMore | () => Promise<void> | required | Function to load more data | | hasMore | boolean | required | Whether more data is available | | threshold | number | 0.1 | Intersection Observer threshold (0-1) | | rootMargin | string | '100px' | Margin around the root |

Returns

| Property | Type | Description | |----------|------|-------------| | sentinelRef | RefObject<HTMLDivElement> | Ref to attach to sentinel element | | isLoading | boolean | Loading state | | error | Error \| null | Error state |

Advanced Usage

Custom Threshold & Root Margin

const { sentinelRef, isLoading } = useInfiniteScroll({
  loadMore,
  hasMore,
  threshold: 0.5,      // Trigger when 50% visible
  rootMargin: '200px', // Start loading 200px before visible
});

With Container Scroll

The hook works with both window scroll and container scroll. Just place the sentinel element inside your scrollable container.

<div style={{ height: '500px', overflow: 'auto' }}>
  {items.map(item => <Item key={item.id} {...item} />)}
  <div ref={sentinelRef} />
</div>

TypeScript

Full TypeScript support with exported types:

import {
  useInfiniteScroll,
  UseInfiniteScrollOptions,
  UseInfiniteScrollReturn
} from 'react-scroll-infinity';

Browser Support

Works in all browsers that support Intersection Observer API (95%+ global support).

Author

Sayed Abdul Karim

License

MIT