import { Flex } from "@chakra-ui/react"; import { useState } from "react"; import InfiniteScroll from "react-infinite-scroller"; const ON_PAGE = 6; const MyInfiniteScroller: React.FC = ({ children }) => { const [elementsToShow, setElementsToShow] = useState(ON_PAGE); if (!Array.isArray(children)) throw Error("children for MyInfiniteScroller is not an array"); return ( setElementsToShow(page * ON_PAGE)} hasMore={elementsToShow < children.length} > {children.slice(0, elementsToShow)} ); }; export default MyInfiniteScroller;