import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell, Pagination, Spinner, getKeyValue, } from "@heroui/react"; import useSWR from "swr"; const fetcher = (...args) => fetch(...args).then((res) => res.json()); export default function App() { const [page, setPage] = React.useState(1); const {data, isLoading} = useSWR(`https://swapi.py4e.com/api/people?page=${page}`, fetcher, { keepPreviousData: true, }); const rowsPerPage = 10; const pages = React.useMemo(() => { return data?.count ? Math.ceil(data.count / rowsPerPage) : 0; }, [data?.count, rowsPerPage]); const loadingState = isLoading || data?.results.length === 0 ? "loading" : "idle"; return ( 0 ? (
setPage(page)} />
) : null } > Name Height Mass Birth year } loadingState={loadingState} > {(item) => ( {(columnKey) => {getKeyValue(item, columnKey)}} )}
); }