A react hook to use infinite scroll
npm install use-infinite-scroll> A react hook to use infinite scroll
 
``bash`
npm install --save use-infinite-scroll
yarn add use-infinite-scroll
https://y2507wpz01.codesandbox.io/
`jsx
import React, { useState, useEffect } from 'react'
import useInfiniteScroll from 'use-infinite-scroll'
const Example = () => {
// Note: If you don't set initial value for items,
// use useEffect(fetchData, []) to load data initially,
// see example/src/App.js for usecase
const [ items, setItems ] = useState(Array.from(Array(30).keys(), n => n + 1));
const [isFetching, setIsFetching] = useInfiniteScroll(fetchData)
// replace this with your own data fetch function
function fetchData() {
setTimeout(() => {
setItems(prevItems =>
([...prevItems, ...Array.from(Array(20).keys(), n => n + prevItems.length + 1)])
);
setIsFetching(false);
}, 2000);
}
return (
MIT © abdullahtariq1171
---
created using create-react-hook.