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

use-dynamic-infinite-scroll

v1.0.4

Published

[![npm version](https://img.shields.io/npm/v/use-dynamic-infinite-scroll)](https://www.npmjs.com/package/use-dynamic-infinite-scroll) [![npm downloads](https://img.shields.io/npm/dt/use-dynamic-infinite-scroll)](https://www.npmjs.com/package/use-dynamic-

Readme

use-dynamic-infinite-scroll

npm version npm downloads

📖 Description

use-dynamic-infinite-scroll is a React custom hook that helps you implement infinite scrolling effortlessly. It automatically loads more data as the user scrolls to the bottom of the page. The hook fetches data using a provided fetch function and seamlessly appends new data to the existing content.

This package allows you to integrate dynamic, efficient infinite scrolling in your React projects with minimal configuration.


✨ Features

  • Automatic Data Fetching: Automatically fetches more data when the user reaches the bottom of the page.
  • Customizable Fetch Logic: Simply pass your fetch function to the hook to handle your own API logic.
  • Prevents Multiple API Calls: Ensures that a new API call is only made after the previous one completes.

📦 Installation

Install use-dynamic-infinite-scroll via npm:

npm install use-dynamic-infinite-scroll 

🛠️ Basic Usage

  1. Import the hook
import useDynamicInfiniteScroll from 'use-dynamic-infinite-scroll';
  1. Create Your Custom Fetch Function Your API should return data in this structure:

    data: Array of your items.

    hasMore: Boolean indicating if more data exists.


const fetchReports = async (page: number, params: any) => {
  try{
  const response: any = await apigetData(
  page.toString(),
  pageSize,
  params.year
);
const reports: Report[] = response.data;
const hasMore = response.hasNext;

return { data: reports, hasMore };
  } catch(error){console.log("error fetching the data")}

} 
  1. place your dynamuc get method in your services file
  export const apigetData = (page: number, search: string, year: string): Promise<AxiosResponse<MyResponseType>> => {
    return axios.get(`/url?page=${page}&search=${search}&year=${year}`);
}
  1. Implement in your component
function ProductList() {
  const fetchData = useCallback(
    (page: number) => fetchCustomData(page, param1, param2, param3),
    [param1, param2, param3]
  );

const { data, scrollLoading,initialLoading, hasMore, loaderRef, updateParams } = useDynamicInfiniteScroll(
    fetchReports,
    0
  );

  const handleFilter = (params1: string, params2: string) => {
    setParams({ params1: params1, params2: params2 });
  };

   return (
    <div>
      {/* Initial Loading */}
      {initialLoading ? (
        <div>Loading data...</div>
      ) : (
        <>
          {/* Actual data mapping */}
          {data.map((item, index) => (
            <div key={index}>
              {item.title}

              {/* loaderRef at last element */}
              {index === data.length - 1 && <div ref={loaderRef}></div>}
            </div>
          ))}

          {/* Scroll loading */}
          {scrollLoading && <div>Loading more data...</div>}

          {/* No More Data */}
          {!hasMore && !initialLoading && (
            <div>No more data available.</div>
          )}
        </>
      )}
    </div>
  );
}

export default ProductList;

📑 API

useDynamicInfiniteScroll(fetchFunction: Function, initialPage: number = 1)

Parameters: fetchFunction: A function that accepts a page number and returns a promise resolving to an object containing:

data: An array of items.

hasMore: A boolean indicating whether more items can be loaded.

initialPage (optional): The initial page number to start fetching data from (default is 1).

Returns:

  1. data: Array of loaded data.

  2. loading: Boolean indicating whether data is currently being loaded.

  3. loaderRef: A React ref to be attached to the last element in your list to trigger infinite scroll.

  4. setParams (optional): A function to dynamically update query parameters for your API calls.

🤝 Contribution

Contributions are welcome! If you'd like to contribute:

  1. Fork the repository.

  2. Clone your fork:

git clone https://github.com/blessedrajp/use-dynamic-infinite-scroll.git
  1. Create a new branch and commit your changes.

  2. Open a pull request to the main repository.

📄 License

MIT License. See the LICENSE file for more information.

📬 Support

If you have any issues or questions, feel free to open an issue on the GitHub Issues page.

📌 Notes

✅ Replace your-username in the GitHub URLs with your actual GitHub username. ✅ Ensure your repository includes a LICENSE file if you intend to open-source it.

🔗 Quick Links

Steps to Follow:

  1. Copy this file and paste it into your README.md.
  2. Replace your-username in the GitHub URLs with your actual GitHub username.
  3. Ensure the repository has a LICENSE file (MIT or another license) if you intend to have an open-source license.

Let me know if you'd like any further changes!

Happy Coding! 🚀