Super simple React hook for creating an infinite scroll experience based on the IntersectionObserver API
npm install @closeio/use-infinite-scroll 
Super simple React hook for creating an infinite scroll experience based on the IntersectionObserver API.
Interested in working on projects like this? Close is looking for great engineers to join our team!
``bash`
yarn add @closeio/use-infinite-scroll
- Extremely lightweight (less than 1KB minzipped).
- It uses the IntersectionObserver API, so it doesn't need to listen to scroll events – which are known to cause performance issues.
- No other 3rd-party dependencies.
`jsx
import React from 'react';
import useInfiniteScroll from '@closeio/use-infinite-scroll';
const [items, setItems] = useState([]);
const [hasMore, setHasMore] = useState(false);
const [page, loaderRef, scrollerRef] = useInfiniteScroll({ hasMore });
useEffect(async () => {
const data = await myApiCall({ page });
setHasMore(data.hasMore);
setItems(prev => [...prev, data.items]);
}, [page]);
return (
MIT © Close