MCPcopy
hub / github.com/TanStack/table / App

Function App

examples/react/virtualized-infinite-scrolling/src/main.tsx:29–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27const fetchSize = 50
28
29function 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

Callers

nothing calls this directly

Calls 6

fetchDataFunction · 0.90
useReactTableFunction · 0.90
flexRenderFunction · 0.90
getCoreRowModelFunction · 0.85
getSortedRowModelFunction · 0.85
getContextMethod · 0.80

Tested by

no test coverage detected