table icon indicating copy to clipboard operation
table copied to clipboard

feat: add existingTable param to useReactTable

Open derekperkins opened this issue 2 months ago โ€ข 2 comments

๐ŸŽฏ Changes

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.

The second commit is AI matching the changes to useReactTable across all the other frameworks. I don't have the framework experience to know if it did a great job or not, but the changes should be pretty simple to review.

โœ… Checklist

  • [x] I have followed the steps in the Contributing guide.
  • [x] I have tested this code locally with pnpm test:pr.

๐Ÿš€ Release Impact

  • [x] This change affects published code, and I have generated a changeset.
  • [ ] This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features
    • Enhanced useReactTable hook with an optional existingTable parameter. Developers can now optionally provide an externally-created Table instance for reuse instead of having the hook automatically create a new one, providing greater flexibility and control over table instance lifecycle management.

derekperkins avatar Nov 04 '25 03:11 derekperkins

๐Ÿฆ‹ Changeset detected

Latest commit: e4686324f0a2c66dc3c0e563cc708005f1c17503

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tanstack/react-table Patch
@tanstack/react-table-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Nov 04 '25 03:11 changeset-bot[bot]

Walkthrough

Adds an optional existingTable parameter across multiple framework adapters (React, Angular, Lit, Qwik, Solid, Svelte, Vue) to allow reusing a provided Table instance instead of always creating a new one; a changeset documents the API addition.

Changes

Cohort / File(s) Change Summary
Changeset Entry
.changeset/beige-singers-admire.md
Patch notes added documenting the new existingTable parameter across adapters.
Framework adapters
packages/react-table/src/index.tsx, packages/angular-table/src/index.ts, packages/lit-table/src/index.ts, packages/qwik-table/src/index.tsx, packages/solid-table/src/index.tsx, packages/svelte-table/src/index.ts, packages/vue-table/src/index.ts
Each API now accepts an optional existingTable?: Table<TData> parameter (typed from @tanstack/table-core) and initializes the internal table with existingTable ?? createTable(resolvedOptions) (or equivalent), preserving prior reactive wiring while enabling table reuse.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AdapterHook as Adapter Hook
  participant createTable as createTable
  note right of AdapterHook `#D6EAF8`: receives options, optional existingTable
  Caller->>AdapterHook: call(options, existingTable?)
  alt existingTable provided
    AdapterHook-->>Caller: return existingTable (wired/reactive)
  else no existingTable
    AdapterHook->>createTable: createTable(resolvedOptions)
    createTable-->>AdapterHook: new Table instance
    AdapterHook-->>Caller: return new Table (wired/reactive)
  end

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20โ€“30 minutes

  • Multiple files across packages changed with the same pattern (parameter addition + conditional initialization).
  • Review focus areas:
    • Correct typing/import of Table from @tanstack/table-core.
    • Ensure no unintended double-initialization across frameworks (Qwik store initialization, Lit controller lifecycle, Svelte/Vue reactivity).
    • Verify exports/signatures and generated declarations if present.

Poem

๐Ÿฐ I found a table, old and neat,
No need to craft another seat,
Pass it in, and off we run,
Reuse and rest โ€” our work is done,
Hop, code, flourish โ€” one table, one beat.

Pre-merge checks and finishing touches

โœ… Passed checks (2 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately describes the main change: adding an existingTable parameter to useReactTable, though the scope extends beyond React to multiple framework adapters.
Description check โœ… Passed The description follows the template structure with all required sections completed, including rationale for the changes and proper checklist completion.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 04 '25 03:11 coderabbitai[bot]