Skip to content

Commit 90eddf6

Browse files
committed
feat: add existingTable param to useReactTable
this enables framework agnostic table adapters to create a table outside of the react context, but then use the existing react package to interact with it as a regular table
1 parent 02c203a commit 90eddf6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.changeset/beige-singers-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/react-table': patch
3+
---
4+
5+
feat: add existingTable param to useReactTable

packages/react-table/src/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TableOptionsResolved,
77
RowData,
88
createTable,
9+
Table,
910
} from '@tanstack/table-core'
1011

1112
export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps>
@@ -55,7 +56,8 @@ function isExoticComponent(component: any) {
5556
}
5657

5758
export function useReactTable<TData extends RowData>(
58-
options: TableOptions<TData>
59+
options: TableOptions<TData>,
60+
existingTable?: Table<TData>
5961
) {
6062
// Compose in the generic options to the user options
6163
const resolvedOptions: TableOptionsResolved<TData> = {
@@ -65,9 +67,9 @@ export function useReactTable<TData extends RowData>(
6567
...options,
6668
}
6769

68-
// Create a new table and store it in state
70+
// Create or use the provided table instance and store it in state
6971
const [tableRef] = React.useState(() => ({
70-
current: createTable<TData>(resolvedOptions),
72+
current: existingTable ?? createTable<TData>(resolvedOptions),
7173
}))
7274

7375
// By default, manage table state here using the table's initial state

0 commit comments

Comments
 (0)