Skip to content

Commit b1e6b79

Browse files
committed
chore: fix react table types
1 parent 81cc88c commit b1e6b79

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

examples/react/grouping/src/main.tsx

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ReactDOM from 'react-dom/client'
44
import './index.css'
55

66
import {
7+
ColumnDef,
78
ColumnFiltering,
89
ColumnGrouping,
910
RowExpanding,
@@ -23,74 +24,76 @@ import type { GroupingState } from '@tanstack/react-table'
2324
import type { Person } from './makeData'
2425

2526
const tableHelper = createTableHelper({
26-
features: {
27+
_features: {
2728
ColumnFiltering,
2829
RowPagination,
2930
RowSorting,
3031
ColumnGrouping,
3132
RowExpanding,
3233
},
33-
rowModels: {
34+
_rowModels: {
3435
Core: createCoreRowModel(),
3536
Filtered: createFilteredRowModel(),
3637
Paginated: createPaginatedRowModel(),
3738
Sorted: createSortedRowModel(),
3839
Grouped: createGroupedRowModel(),
3940
Expanded: createExpandedRowModel(),
4041
},
42+
TData: {} as Person,
4143
})
4244

4345
function App() {
4446
const rerender = React.useReducer(() => ({}), {})[1]
4547

46-
const columns = React.useMemo(
47-
() =>
48-
tableHelper.columnHelper.columns<typeof tableHelper.features, Person>([
49-
{
50-
accessorKey: 'firstName',
51-
header: 'First Name',
52-
cell: (info) => info.getValue(),
53-
/**
54-
* override the value used for row grouping
55-
* (otherwise, defaults to the value derived from accessorKey / accessorFn)
56-
*/
57-
getGroupingValue: (row) => `${row.firstName} ${row.lastName}`,
58-
},
59-
{
60-
accessorFn: (row) => row.lastName,
61-
id: 'lastName',
62-
header: () => <span>Last Name</span>,
63-
cell: (info) => info.getValue(),
64-
},
48+
const columns = React.useMemo<
49+
Array<ColumnDef<typeof tableHelper.features, Person>>
50+
>(
51+
() => [
52+
{
53+
accessorKey: 'firstName',
54+
header: 'First Name',
55+
cell: (info) => info.getValue(),
56+
/**
57+
* override the value used for row grouping
58+
* (otherwise, defaults to the value derived from accessorKey / accessorFn)
59+
*/
60+
getGroupingValue: (row) => `${row.firstName} ${row.lastName}`,
61+
},
62+
{
63+
accessorFn: (row) => row.lastName,
64+
id: 'lastName',
65+
header: () => <span>Last Name</span>,
66+
cell: (info) => info.getValue(),
67+
},
6568

66-
{
67-
accessorKey: 'age',
68-
header: () => 'Age',
69-
aggregatedCell: ({ getValue }) =>
70-
Math.round(getValue<number>() * 100) / 100,
71-
aggregationFn: 'median',
72-
},
69+
{
70+
accessorKey: 'age',
71+
header: () => 'Age',
72+
aggregatedCell: ({ getValue }) =>
73+
Math.round(getValue<number>() * 100) / 100,
74+
aggregationFn: 'median',
75+
},
7376

74-
{
75-
accessorKey: 'visits',
76-
header: () => <span>Visits</span>,
77-
aggregationFn: 'sum',
78-
// aggregatedCell: ({ getValue }) => getValue().toLocaleString(),
79-
},
80-
{
81-
accessorKey: 'status',
82-
header: 'Status',
83-
},
84-
{
85-
accessorKey: 'progress',
86-
header: 'Profile Progress',
87-
cell: ({ getValue }) =>
88-
Math.round(getValue<number>() * 100) / 100 + '%',
89-
aggregationFn: 'mean',
90-
aggregatedCell: ({ getValue }) =>
91-
Math.round(getValue<number>() * 100) / 100 + '%',
92-
},
93-
]),
77+
{
78+
accessorKey: 'visits',
79+
header: () => <span>Visits</span>,
80+
aggregationFn: 'sum',
81+
// aggregatedCell: ({ getValue }) => getValue().toLocaleString(),
82+
},
83+
{
84+
accessorKey: 'status',
85+
header: 'Status',
86+
},
87+
{
88+
accessorKey: 'progress',
89+
header: 'Profile Progress',
90+
cell: ({ getValue }) =>
91+
Math.round(getValue<number>() * 100) / 100 + '%',
92+
aggregationFn: 'mean',
93+
aggregatedCell: ({ getValue }) =>
94+
Math.round(getValue<number>() * 100) / 100 + '%',
95+
},
96+
],
9497
[],
9598
)
9699

packages/react-table/src/tableHelper.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ export type TableHelper<
2424
export function createTableHelper<
2525
TFeatures extends TableFeatures,
2626
TData extends RowData,
27-
>({
28-
TData,
29-
...tableHelperOptions
30-
}: TableHelperOptions<TFeatures, TData>): TableHelper<TFeatures, TData> {
27+
>(
28+
tableHelperOptions: TableHelperOptions<TFeatures, TData>,
29+
): TableHelper<TFeatures, TData> {
3130
const tableHelper = _createTableHelper(useTable, tableHelperOptions)
3231
return {
3332
...tableHelper,
3433
useTable: tableHelper.tableCreator,
35-
}
34+
} as any
3635
}
3736

3837
// test

packages/react-table/src/useTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function useTable<
3333
TFeatures extends TableFeatures,
3434
TData extends RowData,
3535
>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {
36-
const [state, setState] = React.useState<TableState<TFeatures>>(
36+
const [state, setState] = React.useState<TableState<TFeatures>>(() =>
3737
getInitialTableState(builtInFeatures, tableOptions.initialState),
3838
)
3939

0 commit comments

Comments
 (0)