import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell, getKeyValue, Spinner, } from "@heroui/react"; import {SortIcon} from "@heroui/shared-icons"; import {useAsyncList} from "@react-stately/data"; export default function App() { const [isLoading, setIsLoading] = React.useState(true); let list = useAsyncList({ async load({signal}) { let res = await fetch("https://swapi.py4e.com/api/people/?search", { signal, }); let json = await res.json(); setIsLoading(false); return { items: json.results, }; }, async sort({items, sortDescriptor}) { return { items: items.sort((a, b) => { let first = a[sortDescriptor.column]; let second = b[sortDescriptor.column]; let cmp = (parseInt(first) || first) < (parseInt(second) || second) ? -1 : 1; if (sortDescriptor.direction === "descending") { cmp *= -1; } return cmp; }), }; }, }); return ( Name Height Mass Birth year } > {(item) => ( {(columnKey) => {getKeyValue(item, columnKey)}} )}
); }