()
| 27 | const fetchSize = 50 |
| 28 | |
| 29 | function App() { |
| 30 | //we need a reference to the scrolling element for logic down below |
| 31 | const tableContainerRef = React.useRef<HTMLDivElement>(null) |
| 32 | |
| 33 | const [sorting, setSorting] = React.useState<SortingState>([]) |
| 34 | |
| 35 | const columns = React.useMemo<ColumnDef<Person>[]>( |
| 36 | () => [ |
| 37 | { |
| 38 | accessorKey: 'id', |
| 39 | header: 'ID', |
| 40 | size: 60, |
| 41 | }, |
| 42 | { |
| 43 | accessorKey: 'firstName', |
| 44 | cell: info => info.getValue(), |
| 45 | }, |
| 46 | { |
| 47 | accessorFn: row => row.lastName, |
| 48 | id: 'lastName', |
| 49 | cell: info => info.getValue(), |
| 50 | header: () => <span>Last Name</span>, |
| 51 | }, |
| 52 | { |
| 53 | accessorKey: 'age', |
| 54 | header: () => 'Age', |
| 55 | size: 50, |
| 56 | }, |
| 57 | { |
| 58 | accessorKey: 'visits', |
| 59 | header: () => <span>Visits</span>, |
| 60 | size: 50, |
| 61 | }, |
| 62 | { |
| 63 | accessorKey: 'status', |
| 64 | header: 'Status', |
| 65 | }, |
| 66 | { |
| 67 | accessorKey: 'progress', |
| 68 | header: 'Profile Progress', |
| 69 | size: 80, |
| 70 | }, |
| 71 | { |
| 72 | accessorKey: 'createdAt', |
| 73 | header: 'Created At', |
| 74 | cell: info => info.getValue<Date>().toLocaleString(), |
| 75 | size: 200, |
| 76 | }, |
| 77 | ], |
| 78 | [] |
| 79 | ) |
| 80 | |
| 81 | //react-query has a useInfiniteQuery hook that is perfect for this use case |
| 82 | const { data, fetchNextPage, isFetching, isLoading } = |
| 83 | useInfiniteQuery<PersonApiResponse>({ |
| 84 | queryKey: [ |
| 85 | 'people', |
| 86 | sorting, //refetch when sorting changes |
nothing calls this directly
no test coverage detected