Skip to content

Migrating react-table 0.3 → 0.4

Edit on GitHub

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.


  1. Update @volvo-cars/css to 3.2 or later.
  2. Install @tanstack/react-table 9.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.
  3. Switch to useLegacyTable. Import it and your row model factories from @tanstack/react-table/legacy, and type columns with LegacyColumnDef. Your v8 options keep working, and SimpleTable and SimplePagination accept the result. TanStack deprecates useLegacyTable and it bundles every feature, so treat it as a temporary step.
  4. Remove @volvo-cars/edls-css if you only loaded it for tables. See Moving from edls-css to css.
  5. Move to useTable at your own pace. See Moving to useTable.

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(),
});

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 columnSizingFeature and columnResizingFeature for resize handles.
  • Register the sort functions your columns use in sortFns, such as sortFn_text for text and sortFn_alphanumeric for text with numbers. The all-in-one sortFns export is deprecated. Numbers sort without registering anything.
  • Row selection state stores true for selected rows and leaves out the rest.
  • Row checkboxes select a range with Shift. Set enableRowRangeSelection: false to select one row at a time.
  • A select-all checkbox is indeterminate when table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected().
  • SimpleTable and SimplePagination update when the state selected by useTable changes, which by default is all of it. If you pass useTable a selector, include the state they show, such as sorting, rowSelection, expanded and pagination.

See the TanStack Table 9 migration guide for custom aggregation, feature registries and other advanced changes.


  • Column meta is typed with className and style. SimpleTable applies them to header and body cells.
  • SimpleTable passes other props, such as aria-label, to the <table> element.
  • Add Infinity to pageSizeOptions to show an “All” option in SimplePagination.

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.