()
| 22 | //This is a dynamic row height example, which is more complicated, but allows for a more realistic table. |
| 23 | //See https://tanstack.com/virtual/v3/docs/examples/react/table for a simpler fixed row height example. |
| 24 | function App() { |
| 25 | const columns = React.useMemo<ColumnDef<Person>[]>( |
| 26 | () => [ |
| 27 | { |
| 28 | accessorKey: 'id', |
| 29 | header: 'ID', |
| 30 | size: 60, |
| 31 | }, |
| 32 | { |
| 33 | accessorKey: 'firstName', |
| 34 | cell: info => info.getValue(), |
| 35 | }, |
| 36 | { |
| 37 | accessorFn: row => row.lastName, |
| 38 | id: 'lastName', |
| 39 | cell: info => info.getValue(), |
| 40 | header: () => <span>Last Name</span>, |
| 41 | }, |
| 42 | { |
| 43 | accessorKey: 'age', |
| 44 | header: () => 'Age', |
| 45 | size: 50, |
| 46 | }, |
| 47 | { |
| 48 | accessorKey: 'visits', |
| 49 | header: () => <span>Visits</span>, |
| 50 | size: 50, |
| 51 | }, |
| 52 | { |
| 53 | accessorKey: 'status', |
| 54 | header: 'Status', |
| 55 | }, |
| 56 | { |
| 57 | accessorKey: 'progress', |
| 58 | header: 'Profile Progress', |
| 59 | size: 80, |
| 60 | }, |
| 61 | { |
| 62 | accessorKey: 'createdAt', |
| 63 | header: 'Created At', |
| 64 | cell: info => info.getValue<Date>().toLocaleString(), |
| 65 | size: 250, |
| 66 | }, |
| 67 | ], |
| 68 | [] |
| 69 | ) |
| 70 | |
| 71 | // The virtualizer will need a reference to the scrollable container element |
| 72 | const tableContainerRef = React.useRef<HTMLDivElement>(null) |
| 73 | |
| 74 | const [data, setData] = React.useState(() => makeData(50_000)) |
| 75 | |
| 76 | const refreshData = React.useCallback(() => { |
| 77 | setData(makeData(50_000)) |
| 78 | }, []) |
| 79 | |
| 80 | const table = useReactTable({ |
| 81 | data, |
nothing calls this directly
no test coverage detected