A custom hook for implementing infinite scrolling in React applications.
You can install use-infinite-scroll using npm or yarn:
npm install @mikexrmn/use-infinite-scroll
# OR
yarn add @mikexrmn/use-infinite-scrollimport React from "react";
import useInfiniteScroll from "@mikexrmn/use-infinite-scroll";
function MyComponent() {
const fetchData = async (page) => {
// Replace this with your data fetching logic
};
const { data, loading } = useInfiniteScroll(fetchData);
return <div>{/_ Render your data and loading indicator here _/}</div>;
}
export default MyComponent;fetchDataFunction: A function that fetches data based on the current page number.
An object with the following properties:
data: An array of data items.loading: A boolean indicating whether data is currently being loaded.
An object with the following properties:
data: An array of data items.loading: A boolean indicating whether data is currently being loaded.
Contributions are welcome! Feel free to open issues and pull requests.
This project is licensed under the MIT License.