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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@osama-yousuf/react-infinite-scroll-hook

v0.1.8

Published

A powerful, production‑ready **React Infinite Scroll Hook** with:

Readme

@osama-yousuf/react-infinite-scroll-hook

A powerful, production‑ready React Infinite Scroll Hook with:

✅ Axios support ✅ Token / Bearer authentication ✅ Custom API routes ✅ GET / POST / PUT / DELETE ✅ Params OR Body pagination ✅ AbortController handling ✅ Works with any API response shape ✅ Fully TypeScript typed (IDE suggestions enabled)


📦 Installation

npm install @osama-yousuf/react-infinite-scroll-hook axios react

If you're using TypeScript, also install:

npm install -D typescript @types/react

✅ Basic Usage (GET API)

import { useInfiniteScroll } from "@osama-yousuf/react-infinite-scroll-hook";

const App = () => {
  const { data, lastElementRef, loading } = useInfiniteScroll({
    url: "https://api.example.com/users",
    method: "GET",
    params: { status: "active" },
    accessorKey: "data.data",
  });

  return (
    <>
      {data.map((item, index) => (
        <div
          key={item.id}
          ref={data.length === index + 1 ? lastElementRef : null}
        >
          {item.name}
        </div>
      ))}

      {loading && <p>Loading...</p>}
    </>
  );
};

✅ POST API With Body + Token

const { data, refresh } = useInfiniteScroll({
  url: "https://api.example.com/orders",
  method: "POST",
  body: {
    startDate: "2024-01-01",
    endDate: "2025-01-01",
  },
  token: "YOUR_BEARER_TOKEN",
  accessorKey: "data.data",
});

✅ With Custom Axios Instance

import axios from "axios";

const apiInstance = axios.create({
  baseURL: "https://api.example.com",
});
useInfiniteScroll({
  url: "/orders",
  instance: apiInstance,
  method: "POST",
});

✅ With Search + Filters

const params = {
  query: searchValue,
  status: selectedStatus,
};

useInfiniteScroll({
  url: "/users",
  params,
});

✅ Hook Options

| Option | Type | Description | | ----------- | ------------- | ---------------------- | | url | string | API endpoint | | method | string | GET, POST, PUT, DELETE | | params | object | Query parameters | | body | object | Request body | | token | string | Bearer token | | instance | AxiosInstance | Custom axios instance | | accessorKey | string | Path to response data |


✅ Returned Values

{
  data,
  lastElementRef,
  loading,
  hasMore,
  refresh
}

| Key | Description | | -------------- | ---------------------- | | data | Loaded items | | lastElementRef | Attach to last element | | loading | API loading state | | hasMore | Indicates more data | | refresh | Manually reload |


✅ Pagination Key Support

Default uses pageNo. If your API uses another key:

params: {
  page: 1
}

✅ Manual Refresh

<button onClick={refresh}>Refresh</button>

✅ Debounced Search Example

const [search, setSearch] = useState("");
const [debouncedSearch, setDebouncedSearch] = useState("");

useEffect(() => {
  const timer = setTimeout(() => setDebouncedSearch(search), 500);
  return () => clearTimeout(timer);
}, [search]);

✅ Abort Controller Auto Handling

Previous API requests are automatically cancelled when new API is triggered.


✅ TypeScript Support

Fully typed for:

✅ Axios Instance ✅ Props ✅ API response ✅ State ✅ IDE auto‑suggestions


✅ Example API Response

{
  "data": {
    "data": [
      { "id": 1, "name": "John" }
    ]
  }
}

Accessor used:

accessorKey: "data.data"

🧠 Best Practices

✔ Always debounce search inputs ✔ Always use accessorKey ✔ Use instance for large apps ✔ Use token for secured APIs


🧑‍💻 Author

Osama Yousuf GitHub: https://github.com/osamayousuf90


⭐ Support

If you like this package:

✅ Star it on GitHub ✅ Share it with devs ✅ Contribute 🔥


🔍 Keywords

react infinite scroll hook, react infinite scroll, infinite scroll hook, react pagination hook, axios infinite scroll, react data fetching hook, intersection observer, typescript react hook

📜 License

MIT License