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-friendly/infinite-scroll

v3.0.0

Published

A sleek infinite scroll React component

Readme

📜 react-friendly/infinite-scroll

A sleek, generic, and fully controlled infinite scroll component for React — built with TypeScript, imperatively controllable, and customizable to the last pixel.

npm version license types npm downloads

🔧 Installation

npm install @react-friendly/infinite-scroll

or

yarn add @react-friendly/infinite-scroll

🚀 Quick Example

import React from 'react';
import InfiniteScroll from '@react-friendly/infinite-scroll';

interface Post {
    id: number;
    title: string;
}

function PostList() {
    const fetchPosts = async (offset: number): Promise<{ items: Post[], total: number, offset: number }> => {
        const response = await fetch(`/api/posts?offset=${offset}`);
        const data = await response.json();

        return data;
    };

    return (
        <InfiniteScroll
            loadItems={fetchPosts}
            renderItem={(item) => <div key={item.id}>{item.title}</div>}
        />
    );
}

📘 Using page & limit Pagination APIs

If your API uses page, limit, and total instead of offset, no problem — just adapt the request logic accordingly.

import React from 'react';
import InfiniteScroll from '@react-friendly/infinite-scroll';

interface Post {
    id: number;
    title: string;
}

function PostList() {
    const fetchPosts = async (offset: number): Promise<{ items: Post[]; total: number; offset: number }> => {
        const limit = 10;
        // Converts offset-based pagination to page number (1-based index)
        const page = Math.floor(offset / limit) + 1;

        const response = await fetch(`/api/posts?page=${page}&limit=${limit}`);
        const data = await response.json();

        return {
            items: data.data,
            total: data.total,
            offset: offset,
        };
    };

    return (
        <InfiniteScroll
            loadItems={fetchPosts}
            renderItem={(item) => <div key={item.id}>{item.title}</div>}
        />
    );
}

Your API call stays clean, and the component still receives the correct items, total, and original offset. Seamless integration, regardless of backend pagination style.

⚙️ Props

| Prop | Type | Description | |--------------------|---------------------------------------------------|-------------| | loadItems | (offset: number) => Promise<ResponseData<T>> | Async function to fetch more items. | | renderItem | (item: T) => React.ReactNode | Render logic for each item. | | loadingComponent | React.ReactNode | Optional loading indicator. | | errorComponent | React.ReactNode | Optional error fallback UI. | | reverse | boolean | If true, renders items in reverse scroll (e.g., chat apps). | | style | React.CSSProperties | Custom styles for scroll container. | | className | string | Custom class name. |

🔁 Ref API (InfiniteScrollHandle)

Access the component's internal logic via ref:

const ref = useRef<InfiniteScrollHandle<T>>(null);

| Method | Description | | -------- | --------- | | reload() | Reloads the list from scratch. | | replace(predicate, iteToReplace) | Updates a matching item using your predicate logic. | | remove(predicate) | Removes an item based on a predicate. | | getItems() | Returns the currently loaded list of items. | | push(newItem) | Appends a new item manually and updates the total count. | | unshift(newItem) | Prepends a new item to the beginning of the list and updates the total count. |

🔄 Reverse Mode Example (Chat UI)

<InfiniteScroll
    reverse
    loadItems={loadMessages}
    renderItem={(msg) => (
        <div key={msg.id}>
            <b>{msg.user}</b>: {msg.text}
        </div>
    )}
/>

🧱 ResponseData

The loadItems function must return the following structure:

interface ResponseData<T> {
    items: T[];
    total: number;  // total number of items on the server
    offset: number; // current offset (usually passed in the request)
}

🧪 Test with Mock API

const mockLoad = async (offset: number): Promise<ResponseData<number>> => {
    await new Promise(r => setTimeout(r, 500)); // simulate latency
    
    return {
        items: Array.from({ length: 10 }, (_, i) => offset + i + 1),
        total: 100,
        offset,
    };
};

💡 Tips

Use reverse mode for chat interfaces with flexDirection: column-reverse.

The scroll container automatically observes a sentinel element for triggering loads.

You can debounce or throttle loadItems if needed (though the built-in logic prevents duplicate requests).

Ideal for dashboards, timelines, chats, feeds, etc.

🧑‍💻 Contributors

| Photo | Name | Links | | ----- | ---- | ------ | | | Gabriel | GitHub | | | Tarsis | GitHub |

🧾 License

MIT © react-friendly