import React from "react"; import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell, Spinner, getKeyValue, } from "@heroui/react"; import {useInfiniteScroll} from "@heroui/use-infinite-scroll"; import {useAsyncList} from "@react-stately/data"; interface SWCharacter { name: string; height: string; mass: string; birth_year: string; } export default function App() { const [isLoading, setIsLoading] = React.useState(true); const [hasMore, setHasMore] = React.useState(false); let list = useAsyncList({ async load({signal, cursor}) { if (cursor) { setIsLoading(false); } // If no cursor is available, then we're loading the first page. // Otherwise, the cursor is the next URL to load, as returned from the previous page. const res = await fetch(cursor || "https://swapi.py4e.com/api/people/?search=", {signal}); let json = await res.json(); setHasMore(json.next !== null); return { items: json.results, cursor: json.next, }; }, }); const [loaderRef, scrollerRef] = useInfiniteScroll({ hasMore, onLoadMore: list.loadMore, }); return ( ) : null } classNames={{ base: "max-h-[520px] overflow-scroll", table: "min-h-[400px]", }} > Name Height Mass Birth year } > {(item: SWCharacter) => ( {(columnKey) => {getKeyValue(item, columnKey)}} )}
); }