-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: add existingTable param to useReactTable #6123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/react-table': patch | ||
| --- | ||
|
|
||
| feat: add existingTable param to useReactTable |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |||||||||||||||||||||||||||||
| TableOptionsResolved, | ||||||||||||||||||||||||||||||
| RowData, | ||||||||||||||||||||||||||||||
| createTable, | ||||||||||||||||||||||||||||||
| Table, | ||||||||||||||||||||||||||||||
| } from '@tanstack/table-core' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export type Renderable<TProps> = React.ReactNode | React.ComponentType<TProps> | ||||||||||||||||||||||||||||||
|
|
@@ -55,7 +56,8 @@ function isExoticComponent(component: any) { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export function useReactTable<TData extends RowData>( | ||||||||||||||||||||||||||||||
| options: TableOptions<TData> | ||||||||||||||||||||||||||||||
| options: TableOptions<TData>, | ||||||||||||||||||||||||||||||
| existingTable?: Table<TData> | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
|
Comment on lines
58
to
61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add JSDoc documentation for the new parameter. The Add JSDoc to document the parameter: +/**
+ * Hook to create or reuse a TanStack table instance within React.
+ * @param options - Table configuration options
+ * @param existingTable - Optional pre-created table instance. When provided, this table will be used instead of creating a new one. Note: The hook will manage state internally and sync it with the table via setOptions on each render.
+ */
export function useReactTable<TData extends RowData>(
options: TableOptions<TData>,
existingTable?: Table<TData>
) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| // Compose in the generic options to the user options | ||||||||||||||||||||||||||||||
| const resolvedOptions: TableOptionsResolved<TData> = { | ||||||||||||||||||||||||||||||
|
|
@@ -65,9 +67,9 @@ export function useReactTable<TData extends RowData>( | |||||||||||||||||||||||||||||
| ...options, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Create a new table and store it in state | ||||||||||||||||||||||||||||||
| // Create or use the provided table instance and store it in state | ||||||||||||||||||||||||||||||
| const [tableRef] = React.useState(() => ({ | ||||||||||||||||||||||||||||||
| current: createTable<TData>(resolvedOptions), | ||||||||||||||||||||||||||||||
| current: existingTable ?? createTable<TData>(resolvedOptions), | ||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // By default, manage table state here using the table's initial state | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add JSDoc documentation for the new
existingTableparameter.The new
existingTableparameter is a public API addition but lacks documentation explaining its purpose and intended usage pattern. Please add JSDoc comments describing when and how to use this parameter.Apply this diff to add documentation:
📝 Committable suggestion
🤖 Prompt for AI Agents