import { ComponentType, useEffect, useState } from 'react'; import InfiniteScroll from 'react-infinite-scroll-component'; const initialNumberOfItemsDisplayed = 50; export interface InfiniteScrollItemsProps { items: T[]; } interface CustomInfiniteScrollProps { allItems: T[]; child: ComponentType>; } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types const CustomInfiniteScroll = ({ allItems, child }: CustomInfiniteScrollProps) => { const [items, setItems] = useState(allItems.slice(0, 50)); const [index, setIndex] = useState(initialNumberOfItemsDisplayed); const [hasMore, setHasMore] = useState(allItems.length > initialNumberOfItemsDisplayed); const Child = child; useEffect(() => { setItems(allItems.slice(0, initialNumberOfItemsDisplayed)); setHasMore(allItems.length > initialNumberOfItemsDisplayed); }, [allItems]); const fetchMoreData = () => { if (items.length === allItems.length) { setHasMore(false); } else { const newIndex = index + initialNumberOfItemsDisplayed; setIndex(newIndex); setItems(allItems.slice(0, newIndex)); } }; return ( loading...} dataLength={items.length} height={items.length > 25 ? '75vh' : ''} > ); }; export default CustomInfiniteScroll;