Migrating react-table 0.3 → 0.4
Version 0.4 works with TanStack Table 9 and gets all of its styles from @volvo-cars/css. Tables look the same as in 0.3, and @volvo-cars/edls-css is no longer needed for them.
Upgrade steps
Section titled “Upgrade steps”- Update
@volvo-cars/cssto 3.2 or later. - Install
@tanstack/react-table9.1.2 or later, even if you only use the table parts. It’s now a peer dependency, so the table components use the same copy as your tables. - Switch to
useLegacyTable. Import it and your row model factories from@tanstack/react-table/legacy, and type columns withLegacyColumnDef. Your v8 options keep working, andSimpleTableandSimplePaginationaccept the result. TanStack deprecatesuseLegacyTableand it bundles every feature, so treat it as a temporary step. - Remove
@volvo-cars/edls-cssif you only loaded it for tables. See Moving from edls-css to css. - Move to
useTableat your own pace. See Moving touseTable.
If Node loads the CommonJS build, for example during server rendering or in Jest, use Node 20.19+ or 22.12+. TanStack Table 9 only ships ES modules.
Before
import { type ColumnDef, getCoreRowModel, getPaginationRowModel, useReactTable,} from '@tanstack/react-table';
const columns: ColumnDef<Person>[] = [ { accessorKey: 'firstName', header: 'First name' },];
const table = useReactTable({ columns, data, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(),});After
import { type LegacyColumnDef, getCoreRowModel, getPaginationRowModel, useLegacyTable,} from '@tanstack/react-table/legacy';
const columns: LegacyColumnDef<Person>[] = [ { accessorKey: 'firstName', header: 'First name' },];
const table = useLegacyTable({ columns, data, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(),});Moving to useTable
Section titled “Moving to useTable”useTable registers only the features a table uses. Define them with tableFeatures, and put client-side row models in the same object.
import { type ColumnDef, createPaginatedRowModel, createSortedRowModel, rowPaginationFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_text, tableFeatures, useTable,} from '@tanstack/react-table';import { SimplePagination, SimpleTable } from '@volvo-cars/react-table';
const features = tableFeatures({ rowSortingFeature, rowPaginationFeature, sortedRowModel: createSortedRowModel(), paginatedRowModel: createPaginatedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text },});
const columns: ColumnDef<typeof features, Person>[] = [ { accessorKey: 'firstName', header: 'First name' },];
export function People({ data }: { data: Person[] }) { const table = useTable({ features, columns, data }); return ( <> <SimpleTable table={table} aria-label="People" /> <SimplePagination table={table} /> </> );}| TanStack Table 8 | TanStack Table 9 |
|---|---|
useReactTable |
useTable |
getCoreRowModel() |
Not needed. The core row model is always there |
getSortedRowModel() |
sortedRowModel: createSortedRowModel() in features, and the sort functions you use in sortFns |
getPaginationRowModel() |
paginatedRowModel: createPaginatedRowModel() in features |
getExpandedRowModel() |
expandedRowModel: createExpandedRowModel() in features |
ColumnDef<Person> |
ColumnDef<typeof features, Person> |
ReactTablePropsType<Person> |
ReactTablePropsType<Person, typeof features> |
table.getState() |
table.state |
sortingFn |
sortFn |
left and right column pinning |
start and end |
Also check these behavior changes:
- Call row, column, cell and header methods on their instances. Don’t destructure them or pass them as unbound callbacks. Table methods stay bound.
- Register both
columnSizingFeatureandcolumnResizingFeaturefor resize handles. - Register the sort functions your columns use in
sortFns, such assortFn_textfor text andsortFn_alphanumericfor text with numbers. The all-in-onesortFnsexport is deprecated. Numbers sort without registering anything. - Row selection state stores
truefor selected rows and leaves out the rest. - Row checkboxes select a range with Shift. Set
enableRowRangeSelection: falseto select one row at a time. - A select-all checkbox is indeterminate when
table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected(). SimpleTableandSimplePaginationupdate when the state selected byuseTablechanges, which by default is all of it. If you passuseTablea selector, include the state they show, such assorting,rowSelection,expandedandpagination.
See the TanStack Table 9 migration guide for custom aggregation, feature registries and other advanced changes.
New in 0.4
Section titled “New in 0.4”- Column
metais typed withclassNameandstyle.SimpleTableapplies them to header and body cells. SimpleTablepasses other props, such asaria-label, to the<table>element.- Add
InfinitytopageSizeOptionsto show an “All” option inSimplePagination.
Styles
Section titled “Styles”The components use the table and action-bar classes from @volvo-cars/css. The only visual change is the resize handle, which is 24px wide instead of 20px. See Moving from edls-css to css.