@tanstack/react-table 9.0.0-alpha.33 → 9.0.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useTable } from "./useTable.js";
4
4
  import { aggregationFns, createColumnHelper, createExpandedRowModel, createFacetedMinMaxValues, createFacetedRowModel, createFacetedUniqueValues, createFilteredRowModel, createGroupedRowModel, createPaginatedRowModel, createSortedRowModel, filterFns, sortFns, stockFeatures } from "@tanstack/table-core";
5
- import { useMemo } from "react";
5
+ import { useCallback, useMemo } from "react";
6
6
 
7
7
  //#region src/useLegacyTable.ts
8
8
  /**
@@ -132,11 +132,20 @@ function legacyCreateColumnHelper() {
132
132
  function useLegacyTable(options) {
133
133
  const { getCoreRowModel: _getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, getExpandedRowModel, getGroupedRowModel, getFacetedRowModel, getFacetedMinMaxValues, getFacetedUniqueValues, ...restOptions } = options;
134
134
  const _rowModels = {};
135
- if (getFilteredRowModel) _rowModels.filteredRowModel = createFilteredRowModel(filterFns);
136
- if (getSortedRowModel) _rowModels.sortedRowModel = createSortedRowModel(sortFns);
135
+ if (getFilteredRowModel) _rowModels.filteredRowModel = createFilteredRowModel({
136
+ ...filterFns,
137
+ ...options.filterFns
138
+ });
139
+ if (getSortedRowModel) _rowModels.sortedRowModel = createSortedRowModel({
140
+ ...sortFns,
141
+ ...options.sortFns
142
+ });
137
143
  if (getPaginationRowModel) _rowModels.paginatedRowModel = createPaginatedRowModel();
138
144
  if (getExpandedRowModel) _rowModels.expandedRowModel = createExpandedRowModel();
139
- if (getGroupedRowModel) _rowModels.groupedRowModel = createGroupedRowModel(aggregationFns);
145
+ if (getGroupedRowModel) _rowModels.groupedRowModel = createGroupedRowModel({
146
+ ...aggregationFns,
147
+ ...options.aggregationFns
148
+ });
140
149
  if (getFacetedRowModel) _rowModels.facetedRowModel = createFacetedRowModel();
141
150
  if (getFacetedMinMaxValues) _rowModels.facetedMinMaxValues = createFacetedMinMaxValues();
142
151
  if (getFacetedUniqueValues) _rowModels.facetedUniqueValues = createFacetedUniqueValues();
@@ -145,10 +154,27 @@ function useLegacyTable(options) {
145
154
  _features: stockFeatures,
146
155
  _rowModels
147
156
  }, (state) => state);
157
+ const getState = useCallback(() => {
158
+ return {
159
+ ...table.state,
160
+ columns: void 0,
161
+ data: void 0
162
+ };
163
+ }, [table]);
164
+ const setState = useCallback((state) => {
165
+ Object.entries(state).forEach(([key, value]) => {
166
+ table.baseAtoms[key].set(value);
167
+ });
168
+ }, [table]);
148
169
  return useMemo(() => ({
149
170
  ...table,
150
- getState: () => table.state
151
- }), [table]);
171
+ getState,
172
+ setState
173
+ }), [
174
+ table,
175
+ getState,
176
+ setState
177
+ ]);
152
178
  }
153
179
 
154
180
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useLegacyTable.js","names":[],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return (() => () => undefined) as unknown as FacetedMinMaxValuesFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return (() => () => new Map()) as unknown as FacetedUniqueValuesFactory<TData>\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\ntype RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\ntype FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\ntype FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\ntype FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n // Build the _rowModels object based on which legacy options were provided\n const _rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Map v8 row model factories to v9 _rowModels\n // Note: getCoreRowModel is handled automatically in v9, so we ignore it\n\n if (getFilteredRowModel) {\n _rowModels.filteredRowModel = createFilteredRowModel(filterFns)\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel(sortFns)\n }\n\n if (getPaginationRowModel) {\n _rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n _rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n _rowModels.groupedRowModel = createGroupedRowModel(aggregationFns)\n }\n\n if (getFacetedRowModel) {\n _rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n _rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n _rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n } as TableOptions<StockFeatures, TData>,\n (state) => state,\n )\n\n return useMemo(\n () =>\n ({\n ...table,\n getState: () => table.state,\n }) as LegacyReactTable<TData>,\n [table],\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAiDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qCAAoB,IAAI,KAAK;;;;;;;;AAS/B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AA6KtB,SAAgB,2BAAkD;AAChE,QAAO,oBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAGJ,MAAM,aAAwD,EAAE;AAKhE,KAAI,oBACF,YAAW,mBAAmB,uBAAuB,UAAU;AAGjE,KAAI,kBACF,YAAW,iBAAiB,qBAAqB,QAAQ;AAG3D,KAAI,sBACF,YAAW,oBAAoB,yBAAyB;AAG1D,KAAI,oBACF,YAAW,mBAAmB,wBAAwB;AAGxD,KAAI,mBACF,YAAW,kBAAkB,sBAAsB,eAAe;AAGpE,KAAI,mBACF,YAAW,kBAAkB,uBAAuB;AAGtD,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;AAG9D,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;CAI9D,MAAM,QAAQ,SACZ;EACE,GAAG;EACH,WAAW;EACX;EACD,GACA,UAAU,MACZ;AAED,QAAO,eAEF;EACC,GAAG;EACH,gBAAgB,MAAM;EACvB,GACH,CAAC,MAAM,CACR"}
1
+ {"version":3,"file":"useLegacyTable.js","names":[],"sources":["../src/useLegacyTable.ts"],"sourcesContent":["'use client'\n\nimport {\n aggregationFns,\n createColumnHelper,\n createExpandedRowModel,\n createFacetedMinMaxValues,\n createFacetedRowModel,\n createFacetedUniqueValues,\n createFilteredRowModel,\n createGroupedRowModel,\n createPaginatedRowModel,\n createSortedRowModel,\n filterFns,\n sortFns,\n stockFeatures,\n} from '@tanstack/table-core'\nimport { useCallback, useMemo } from 'react'\nimport { useTable } from './useTable'\nimport type {\n AggregationFns,\n Cell,\n Column,\n ColumnDef,\n CreateRowModels_All,\n FilterFns,\n Header,\n HeaderGroup,\n Row,\n RowData,\n RowModel,\n SortFns,\n StockFeatures,\n Table,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ReactTable } from './useTable'\n\n// =============================================================================\n// V8-style row model factory functions\n// These are stub functions that act as markers for useLegacyTable to know\n// which row models to enable. They don't actually do anything - the real\n// implementation is handled by useLegacyTable internally.\n// =============================================================================\n\n/**\n * @deprecated Use `createFilteredRowModel(filterFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the filtered row model.\n */\nexport function getFilteredRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createSortedRowModel(sortFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the sorted row model.\n */\nexport function getSortedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the paginated row model.\n */\nexport function getPaginationRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the expanded row model.\n */\nexport function getExpandedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createGroupedRowModel(aggregationFns)` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the grouped row model.\n */\nexport function getGroupedRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted row model.\n */\nexport function getFacetedRowModel<\n TData extends RowData,\n>(): FacetedRowModelFactory<TData> {\n return (() => () => {}) as unknown as FacetedRowModelFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted min/max values.\n */\nexport function getFacetedMinMaxValues<\n TData extends RowData,\n>(): FacetedMinMaxValuesFactory<TData> {\n return (() => () => undefined) as unknown as FacetedMinMaxValuesFactory<TData>\n}\n\n/**\n * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It acts as a marker to enable the faceted unique values.\n */\nexport function getFacetedUniqueValues<\n TData extends RowData,\n>(): FacetedUniqueValuesFactory<TData> {\n return (() => () => new Map()) as unknown as FacetedUniqueValuesFactory<TData>\n}\n\n/**\n * @deprecated The core row model is always created automatically in v9.\n *\n * This is a stub function for v8 API compatibility with `useLegacyTable`.\n * It does nothing - the core row model is always available.\n */\nexport function getCoreRowModel<\n TData extends RowData,\n>(): RowModelFactory<TData> {\n return (() => () => {}) as unknown as RowModelFactory<TData>\n}\n\n// =============================================================================\n// Type definitions\n// =============================================================================\n\n/**\n * Row model factory function type from v8 API\n */\ntype RowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted row model factory function type from v8 API\n */\ntype FacetedRowModelFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => RowModel<StockFeatures, TData>\n\n/**\n * Faceted min/max values factory function type from v8 API\n */\ntype FacetedMinMaxValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number]\n\n/**\n * Faceted unique values factory function type from v8 API\n */\ntype FacetedUniqueValuesFactory<TData extends RowData> = (\n table: Table<StockFeatures, TData>,\n columnId: string,\n) => () => Map<any, number>\n\n/**\n * Legacy v8-style row model options\n */\nexport interface LegacyRowModelOptions<TData extends RowData> {\n /**\n * Returns the core row model for the table.\n * @deprecated This option is no longer needed in v9. The core row model is always created automatically.\n */\n getCoreRowModel?: RowModelFactory<TData>\n /**\n * Returns the filtered row model for the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n getFilteredRowModel?: RowModelFactory<TData>\n /**\n * Returns the sorted row model for the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n getSortedRowModel?: RowModelFactory<TData>\n /**\n * Returns the paginated row model for the table.\n * @deprecated Use `_rowModels.paginatedRowModel` with `createPaginatedRowModel()` instead.\n */\n getPaginationRowModel?: RowModelFactory<TData>\n /**\n * Returns the expanded row model for the table.\n * @deprecated Use `_rowModels.expandedRowModel` with `createExpandedRowModel()` instead.\n */\n getExpandedRowModel?: RowModelFactory<TData>\n /**\n * Returns the grouped row model for the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n getGroupedRowModel?: RowModelFactory<TData>\n /**\n * Returns the faceted row model for a column.\n * @deprecated Use `_rowModels.facetedRowModel` with `createFacetedRowModel()` instead.\n */\n getFacetedRowModel?: FacetedRowModelFactory<TData>\n /**\n * Returns the faceted min/max values for a column.\n * @deprecated Use `_rowModels.facetedMinMaxValues` with `createFacetedMinMaxValues()` instead.\n */\n getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>\n /**\n * Returns the faceted unique values for a column.\n * @deprecated Use `_rowModels.facetedUniqueValues` with `createFacetedUniqueValues()` instead.\n */\n getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>\n /**\n * Additional filter functions to apply to the table.\n * @deprecated Use `_rowModels.filteredRowModel` with `createFilteredRowModel(filterFns)` instead.\n */\n filterFns?: FilterFns\n /**\n * Additional sort functions to apply to the table.\n * @deprecated Use `_rowModels.sortedRowModel` with `createSortedRowModel(sortFns)` instead.\n */\n sortFns?: SortFns\n /**\n * Additional aggregation functions to apply to the table.\n * @deprecated Use `_rowModels.groupedRowModel` with `createGroupedRowModel(aggregationFns)` instead.\n */\n aggregationFns?: AggregationFns\n}\n\n/**\n * Legacy v8-style table options that work with useLegacyTable.\n *\n * This type omits `_features` and `_rowModels` and instead accepts the v8-style\n * `get*RowModel` function options.\n *\n * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with explicit `_features` and `_rowModels` instead.\n */\nexport type LegacyTableOptions<TData extends RowData> = Omit<\n TableOptions<StockFeatures, TData>,\n '_features' | '_rowModels'\n> &\n LegacyRowModelOptions<TData>\n\n/**\n * Legacy table instance type that includes the v8-style `getState()` method.\n *\n * @deprecated Use `useTable` with explicit state selection instead.\n */\nexport type LegacyReactTable<TData extends RowData> = ReactTable<\n StockFeatures,\n TData,\n TableState<StockFeatures>\n> & {\n /**\n * Returns the current table state.\n * @deprecated In v9, access state directly via `table.state` or use `table.store.state` for the full state.\n */\n getState: () => TableState<StockFeatures>\n /**\n * Sets the current table state.\n * @deprecated In v9, access state directly via `table.baseAtoms`\n */\n setState: (state: TableState<StockFeatures>) => void\n}\n\n// =============================================================================\n// Legacy type aliases - StockFeatures hardcoded for simpler prop typing with useLegacyTable\n// =============================================================================\n\n/** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumn<TData extends RowData, TValue = unknown> = Column<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Row<TFeatures, TData> with useTable instead. */\nexport type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>\n\n/** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyCell<TData extends RowData, TValue = unknown> = Cell<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyHeader<TData extends RowData, TValue = unknown> = Header<\n StockFeatures,\n TData,\n TValue\n>\n\n/** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */\nexport type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<\n StockFeatures,\n TData\n>\n\n/** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */\nexport type LegacyColumnDef<\n TData extends RowData,\n TValue = unknown,\n> = ColumnDef<StockFeatures, TData, TValue>\n\n/** @deprecated Use Table<TFeatures, TData> with useTable instead. */\nexport type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>\n\n// =============================================================================\n// Legacy column helper - StockFeatures hardcoded\n// =============================================================================\n\n/**\n * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead.\n *\n * A column helper with StockFeatures pre-bound for use with useLegacyTable.\n * Only requires TData—no need to specify TFeatures.\n */\nexport function legacyCreateColumnHelper<TData extends RowData>() {\n return createColumnHelper<StockFeatures, TData>()\n}\n\n// =============================================================================\n// useLegacyTable hook\n// =============================================================================\n\n/**\n * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8.\n *\n * Use the new `useTable` hook instead with explicit `_features` and `_rowModels`:\n *\n * ```tsx\n * // New v9 API\n * const _features = tableFeatures({\n * columnFilteringFeature,\n * rowSortingFeature,\n * rowPaginationFeature,\n * })\n *\n * const table = useTable({\n * _features,\n * _rowModels: {\n * filteredRowModel: createFilteredRowModel(filterFns),\n * sortedRowModel: createSortedRowModel(sortFns),\n * paginatedRowModel: createPaginatedRowModel(),\n * },\n * columns,\n * data,\n * })\n * ```\n *\n * Key differences from v8:\n * - Features are tree-shakeable - only import what you use\n * - Row models are explicitly passed via `_rowModels`\n * - Use `table.Subscribe` for fine-grained re-renders\n * - State is accessed via `table.state` after selecting with the 2nd argument\n *\n * @param options - Legacy v8-style table options\n * @returns A table instance with the full state subscribed and a `getState()` method\n */\nexport function useLegacyTable<TData extends RowData>(\n options: LegacyTableOptions<TData>,\n): LegacyReactTable<TData> {\n const {\n // Extract legacy row model options\n getCoreRowModel: _getCoreRowModel,\n getFilteredRowModel,\n getSortedRowModel,\n getPaginationRowModel,\n getExpandedRowModel,\n getGroupedRowModel,\n getFacetedRowModel,\n getFacetedMinMaxValues,\n getFacetedUniqueValues,\n // Rest of the options\n ...restOptions\n } = options\n\n // Build the _rowModels object based on which legacy options were provided\n const _rowModels: CreateRowModels_All<StockFeatures, TData> = {}\n\n // Map v8 row model factories to v9 _rowModels\n // Note: getCoreRowModel is handled automatically in v9, so we ignore it\n\n if (getFilteredRowModel) {\n _rowModels.filteredRowModel = createFilteredRowModel({\n ...filterFns,\n ...options.filterFns,\n })\n }\n\n if (getSortedRowModel) {\n _rowModels.sortedRowModel = createSortedRowModel({\n ...sortFns,\n ...options.sortFns,\n })\n }\n\n if (getPaginationRowModel) {\n _rowModels.paginatedRowModel = createPaginatedRowModel()\n }\n\n if (getExpandedRowModel) {\n _rowModels.expandedRowModel = createExpandedRowModel()\n }\n\n if (getGroupedRowModel) {\n _rowModels.groupedRowModel = createGroupedRowModel({\n ...aggregationFns,\n ...options.aggregationFns,\n })\n }\n\n if (getFacetedRowModel) {\n _rowModels.facetedRowModel = createFacetedRowModel()\n }\n\n if (getFacetedMinMaxValues) {\n _rowModels.facetedMinMaxValues = createFacetedMinMaxValues()\n }\n\n if (getFacetedUniqueValues) {\n _rowModels.facetedUniqueValues = createFacetedUniqueValues()\n }\n\n // Call useTable with the v9 API, subscribing to all state changes\n const table = useTable<StockFeatures, TData, TableState<StockFeatures>>(\n {\n ...restOptions,\n _features: stockFeatures,\n _rowModels,\n } as TableOptions<StockFeatures, TData>,\n (state) => state,\n )\n\n const getState = useCallback(() => {\n // all state except for columns and data\n return {\n ...table.state,\n columns: undefined,\n data: undefined,\n }\n }, [table])\n\n const setState = useCallback(\n (state: TableState<StockFeatures>) => {\n Object.entries(state).forEach(([key, value]) => {\n // @ts-expect-error - baseAtoms is indexed by dynamic string keys\n table.baseAtoms[key].set(value)\n })\n },\n [table],\n )\n\n return useMemo(\n () =>\n ({\n ...table,\n getState,\n setState,\n }) as LegacyReactTable<TData>,\n [table, getState, setState],\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,oBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,wBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,sBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEY;AAC1B,qBAAoB;;;;;;;;AAStB,SAAgB,qBAEmB;AACjC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qBAAoB;;;;;;;;AAStB,SAAgB,yBAEuB;AACrC,qCAAoB,IAAI,KAAK;;;;;;;;AAS/B,SAAgB,kBAEY;AAC1B,qBAAoB;;;;;;;;AAiMtB,SAAgB,2BAAkD;AAChE,QAAO,oBAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCnD,SAAgB,eACd,SACyB;CACzB,MAAM,EAEJ,iBAAiB,kBACjB,qBACA,mBACA,uBACA,qBACA,oBACA,oBACA,wBACA,wBAEA,GAAG,gBACD;CAGJ,MAAM,aAAwD,EAAE;AAKhE,KAAI,oBACF,YAAW,mBAAmB,uBAAuB;EACnD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,kBACF,YAAW,iBAAiB,qBAAqB;EAC/C,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,sBACF,YAAW,oBAAoB,yBAAyB;AAG1D,KAAI,oBACF,YAAW,mBAAmB,wBAAwB;AAGxD,KAAI,mBACF,YAAW,kBAAkB,sBAAsB;EACjD,GAAG;EACH,GAAG,QAAQ;EACZ,CAAC;AAGJ,KAAI,mBACF,YAAW,kBAAkB,uBAAuB;AAGtD,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;AAG9D,KAAI,uBACF,YAAW,sBAAsB,2BAA2B;CAI9D,MAAM,QAAQ,SACZ;EACE,GAAG;EACH,WAAW;EACX;EACD,GACA,UAAU,MACZ;CAED,MAAM,WAAW,kBAAkB;AAEjC,SAAO;GACL,GAAG,MAAM;GACT,SAAS;GACT,MAAM;GACP;IACA,CAAC,MAAM,CAAC;CAEX,MAAM,WAAW,aACd,UAAqC;AACpC,SAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,WAAW;AAE9C,SAAM,UAAU,KAAK,IAAI,MAAM;IAC/B;IAEJ,CAAC,MAAM,CACR;AAED,QAAO,eAEF;EACC,GAAG;EACH;EACA;EACD,GACH;EAAC;EAAO;EAAU;EAAS,CAC5B"}
package/dist/useTable.cjs CHANGED
@@ -11,12 +11,12 @@ let _tanstack_react_store = require("@tanstack/react-store");
11
11
  function useTable(tableOptions, selector = () => ({})) {
12
12
  const [table] = (0, react.useState)(() => {
13
13
  const tableInstance = (0, _tanstack_table_core.constructTable)(tableOptions);
14
- tableInstance.Subscribe = function SubscribeBound(props) {
14
+ tableInstance.Subscribe = ((props) => {
15
15
  return require_Subscribe.Subscribe({
16
16
  ...props,
17
17
  table: tableInstance
18
18
  });
19
- };
19
+ });
20
20
  tableInstance.FlexRender = require_FlexRender.FlexRender;
21
21
  return tableInstance;
22
22
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribeProps } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax\n * <tr key={row.id}>\n // render the row\n * </tr>\n * ))}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n }) => ReturnType<FunctionComponent>\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = function SubscribeBound<TSelected>(\n props: Omit<SubscribeProps<TFeatures, TData, TSelected>, 'table'>,\n ) {\n return Subscribe({ ...props, table: tableInstance })\n }\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AA8EA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B,aAAa;AAMlD,gBAAc,YAAY,SAAS,eACjC,OACA;AACA,UAAOA,4BAAU;IAAE,GAAG;IAAO,OAAO;IAAe,CAAC;;AAGtD,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,+CAAoB,MAAM,OAAO,4BAA4B,EACjE,SAASC,+BACV,CAAC;AAEF,kCACS;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
1
+ {"version":3,"file":"useTable.cjs","names":["Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `atom` to subscribe to a single slice atom instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe atom={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe atom={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Atom **without** `selector` is a separate overload so children receive `TAtomValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the atom.\n *\n * The **atom** overloads are listed first so `TAtomValue` is inferred from `atom`.\n */\n Subscribe: {\n <TAtomValue>(props: {\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector?: undefined\n children: ((state: TAtomValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TAtomValue, TSubSelected>(props: {\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector: (state: TAtomValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;;AAgHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,mCAAwB;EAC7B,MAAM,yDAA+B,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAOA,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,+CAAoB,MAAM,OAAO,4BAA4B,EACjE,SAASC,+BACV,CAAC;AAEF,kCACS;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
@@ -1,6 +1,8 @@
1
1
  import { FlexRenderProps } from "./FlexRender.cjs";
2
- import { CellData, NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
2
+ import { SubscribePropsWithStore } from "./Subscribe.cjs";
3
+ import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
3
4
  import { FunctionComponent, ReactNode } from "react";
5
+ import { Atom, ReadonlyAtom } from "@tanstack/react-store";
4
6
 
5
7
  //#region src/useTable.d.ts
6
8
  type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
@@ -9,19 +11,48 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
9
11
  *
10
12
  * This is useful for opting into state re-renders for specific parts of the table state.
11
13
  *
14
+ * Pass `atom` to subscribe to a single slice atom instead of the full `table.store`.
15
+ *
12
16
  * @example
13
17
  * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
14
- * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax
15
- * <tr key={row.id}>
16
- // render the row
17
- * </tr>
18
- * ))}
18
+ * {({ rowSelection }) => (
19
+ * <tr key={row.id}>...</tr>
20
+ * )}
21
+ * </table.Subscribe>
22
+ *
23
+ * @example
24
+ * <table.Subscribe atom={table.atoms.rowSelection}>
25
+ * {(rowSelection) => <div>...</div>}
26
+ * </table.Subscribe>
27
+ *
28
+ * @example
29
+ * <table.Subscribe atom={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
30
+ * {() => <tr key={row.id}>...</tr>}
19
31
  * </table.Subscribe>
20
32
  */
21
- Subscribe: <TSelected>(props: {
22
- selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
23
- children: ((state: TSelected) => ReactNode) | ReactNode;
24
- }) => ReturnType<FunctionComponent>;
33
+ /**
34
+ * Overloads (not a single union) so `selector` callbacks get correct contextual
35
+ * types in JSX; a union of two `selector` signatures degrades to implicit `any`.
36
+ *
37
+ * Atom **without** `selector` is a separate overload so children receive `TAtomValue`
38
+ * (identity projection). If `selector` were optional on one overload, `TSubSelected`
39
+ * would default to `unknown` instead of inferring from the atom.
40
+ *
41
+ * The **atom** overloads are listed first so `TAtomValue` is inferred from `atom`.
42
+ */
43
+ Subscribe: {
44
+ <TAtomValue>(props: {
45
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
46
+ selector?: undefined;
47
+ children: ((state: TAtomValue) => ReactNode) | ReactNode;
48
+ }): ReturnType<FunctionComponent>;
49
+ <TAtomValue, TSubSelected>(props: {
50
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
51
+ selector: (state: TAtomValue) => TSubSelected;
52
+ children: ((state: TSubSelected) => ReactNode) | ReactNode;
53
+ }): ReturnType<FunctionComponent>;
54
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
55
+ };
25
56
  /**
26
57
  * A React component that renders headers, cells, or footers with custom markup.
27
58
  * Use this utility component instead of manually calling flexRender.
@@ -1,6 +1,8 @@
1
1
  import { FlexRenderProps } from "./FlexRender.js";
2
- import { CellData, NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
2
+ import { SubscribePropsWithStore } from "./Subscribe.js";
3
+ import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
3
4
  import { FunctionComponent, ReactNode } from "react";
5
+ import { Atom, ReadonlyAtom } from "@tanstack/react-store";
4
6
 
5
7
  //#region src/useTable.d.ts
6
8
  type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
@@ -9,19 +11,48 @@ type ReactTable<TFeatures extends TableFeatures, TData extends RowData, TSelecte
9
11
  *
10
12
  * This is useful for opting into state re-renders for specific parts of the table state.
11
13
  *
14
+ * Pass `atom` to subscribe to a single slice atom instead of the full `table.store`.
15
+ *
12
16
  * @example
13
17
  * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
14
- * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax
15
- * <tr key={row.id}>
16
- // render the row
17
- * </tr>
18
- * ))}
18
+ * {({ rowSelection }) => (
19
+ * <tr key={row.id}>...</tr>
20
+ * )}
21
+ * </table.Subscribe>
22
+ *
23
+ * @example
24
+ * <table.Subscribe atom={table.atoms.rowSelection}>
25
+ * {(rowSelection) => <div>...</div>}
26
+ * </table.Subscribe>
27
+ *
28
+ * @example
29
+ * <table.Subscribe atom={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>
30
+ * {() => <tr key={row.id}>...</tr>}
19
31
  * </table.Subscribe>
20
32
  */
21
- Subscribe: <TSelected>(props: {
22
- selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
23
- children: ((state: TSelected) => ReactNode) | ReactNode;
24
- }) => ReturnType<FunctionComponent>;
33
+ /**
34
+ * Overloads (not a single union) so `selector` callbacks get correct contextual
35
+ * types in JSX; a union of two `selector` signatures degrades to implicit `any`.
36
+ *
37
+ * Atom **without** `selector` is a separate overload so children receive `TAtomValue`
38
+ * (identity projection). If `selector` were optional on one overload, `TSubSelected`
39
+ * would default to `unknown` instead of inferring from the atom.
40
+ *
41
+ * The **atom** overloads are listed first so `TAtomValue` is inferred from `atom`.
42
+ */
43
+ Subscribe: {
44
+ <TAtomValue>(props: {
45
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
46
+ selector?: undefined;
47
+ children: ((state: TAtomValue) => ReactNode) | ReactNode;
48
+ }): ReturnType<FunctionComponent>;
49
+ <TAtomValue, TSubSelected>(props: {
50
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>;
51
+ selector: (state: TAtomValue) => TSubSelected;
52
+ children: ((state: TSubSelected) => ReactNode) | ReactNode;
53
+ }): ReturnType<FunctionComponent>;
54
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ReturnType<FunctionComponent>;
55
+ };
25
56
  /**
26
57
  * A React component that renders headers, cells, or footers with custom markup.
27
58
  * Use this utility component instead of manually calling flexRender.
package/dist/useTable.js CHANGED
@@ -10,12 +10,12 @@ import { shallow, useSelector } from "@tanstack/react-store";
10
10
  function useTable(tableOptions, selector = () => ({})) {
11
11
  const [table] = useState(() => {
12
12
  const tableInstance = constructTable(tableOptions);
13
- tableInstance.Subscribe = function SubscribeBound(props) {
13
+ tableInstance.Subscribe = ((props) => {
14
14
  return Subscribe({
15
15
  ...props,
16
16
  table: tableInstance
17
17
  });
18
- };
18
+ });
19
19
  tableInstance.FlexRender = FlexRender;
20
20
  return tableInstance;
21
21
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribeProps } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax\n * <tr key={row.id}>\n // render the row\n * </tr>\n * ))}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children: ((state: TSelected) => ReactNode) | ReactNode\n }) => ReturnType<FunctionComponent>\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = function SubscribeBound<TSelected>(\n props: Omit<SubscribeProps<TFeatures, TData, TSelected>, 'table'>,\n ) {\n return Subscribe({ ...props, table: tableInstance })\n }\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;AA8EA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe,aAAa;AAMlD,gBAAc,YAAY,SAAS,eACjC,OACA;AACA,UAAO,UAAU;IAAE,GAAG;IAAO,OAAO;IAAe,CAAC;;AAGtD,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,QAAQ,YAAY,MAAM,OAAO,4BAA4B,EACjE,SAAS,SACV,CAAC;AAEF,QAAO,eACE;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
1
+ {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["'use client'\n\nimport { useMemo, useState } from 'react'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/react-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/react-store'\nimport type { FunctionComponent, ReactNode } from 'react'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type ReactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A React HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * Pass `atom` to subscribe to a single slice atom instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe atom={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe atom={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (not a single union) so `selector` callbacks get correct contextual\n * types in JSX; a union of two `selector` signatures degrades to implicit `any`.\n *\n * Atom **without** `selector` is a separate overload so children receive `TAtomValue`\n * (identity projection). If `selector` were optional on one overload, `TSubSelected`\n * would default to `unknown` instead of inferring from the atom.\n *\n * The **atom** overloads are listed first so `TAtomValue` is inferred from `atom`.\n */\n Subscribe: {\n <TAtomValue>(props: {\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector?: undefined\n children: ((state: TAtomValue) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TAtomValue, TSubSelected>(props: {\n atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>\n selector: (state: TAtomValue) => TSubSelected\n children: ((state: TSubSelected) => ReactNode) | ReactNode\n }): ReturnType<FunctionComponent>\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ReturnType<FunctionComponent>\n }\n /**\n * A React component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n *\n * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ReactNode\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): ReactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as ReactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as ReactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useSelector(table.store, selectorWithDataAndColumns, {\n compare: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as ReactTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;;;;AAgHA,SAAgB,SAKd,cACA,kBACG,EAAE,GACoC;CACzC,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe,aAAa;AAMlD,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,8BAA8B,WAAkC;EACpE,SAAS,aAAa;EACtB,MAAM,aAAa;EACnB,GAAG,SAAS,MAAM;EACnB;CAED,MAAM,QAAQ,YAAY,MAAM,OAAO,4BAA4B,EACjE,SAAS,SACV,CAAC;AAEF,QAAO,eACE;EACL,GAAG;EACH;EACD,GACD,CAAC,OAAO,MAAM,CACf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
- "version": "9.0.0-alpha.33",
3
+ "version": "9.0.0-alpha.34",
4
4
  "description": "Headless UI for building powerful tables & datagrids for React.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -33,6 +33,10 @@
33
33
  "import": "./dist/legacy.js",
34
34
  "require": "./dist/legacy.cjs"
35
35
  },
36
+ "./static-functions": {
37
+ "import": "./dist/static-functions.js",
38
+ "require": "./dist/static-functions.cjs"
39
+ },
36
40
  "./package.json": "./package.json"
37
41
  },
38
42
  "sideEffects": false,
@@ -45,7 +49,7 @@
45
49
  ],
46
50
  "dependencies": {
47
51
  "@tanstack/react-store": "^0.11.0",
48
- "@tanstack/table-core": "9.0.0-alpha.33"
52
+ "@tanstack/table-core": "9.0.0-alpha.34"
49
53
  },
50
54
  "devDependencies": {
51
55
  "@eslint-react/eslint-plugin": "^4.2.3",
package/src/Subscribe.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  'use client'
2
2
 
3
3
  import { shallow, useSelector } from '@tanstack/react-store'
4
+ import type { Atom, ReadonlyAtom } from '@tanstack/react-store'
4
5
  import type {
5
- NoInfer,
6
6
  RowData,
7
7
  Table,
8
8
  TableFeatures,
@@ -10,35 +10,94 @@ import type {
10
10
  } from '@tanstack/table-core'
11
11
  import type { FunctionComponent, ReactNode } from 'react'
12
12
 
13
- export type SubscribeProps<
13
+ /**
14
+ * Subscribe to `table.store` (full table state). The selector receives the full
15
+ * {@link TableState}.
16
+ */
17
+ export type SubscribePropsWithStore<
14
18
  TFeatures extends TableFeatures,
15
19
  TData extends RowData,
16
- TSelected = {},
20
+ TSelected,
17
21
  > = {
18
- /**
19
- * The table instance to subscribe to. Required when using as a standalone component.
20
- * Not needed when using as `table.Subscribe`.
21
- */
22
22
  table: Table<TFeatures, TData>
23
23
  /**
24
- * A selector function that selects the part of the table state to subscribe to.
25
- * This allows for fine-grained reactivity by only re-rendering when the selected state changes.
26
- */
27
- selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
28
- /**
29
- * The children to render. Can be a function that receives the selected state, or a React node.
24
+ * Select from full table state. Re-renders when the selected value changes
25
+ * (shallow compare).
26
+ *
27
+ * Required in store mode so you never accidentally subscribe to the whole
28
+ * store without an explicit projection.
30
29
  */
30
+ selector: (state: TableState<TFeatures>) => TSelected
31
31
  children: ((state: TSelected) => ReactNode) | ReactNode
32
32
  }
33
33
 
34
+ /**
35
+ * Subscribe to the full value of a slice atom (e.g. `table.atoms.rowSelection`).
36
+ * Omitting `selector` is equivalent to the identity selector — children receive
37
+ * `TAtomValue`.
38
+ */
39
+ export type SubscribePropsWithAtomIdentity<
40
+ TFeatures extends TableFeatures,
41
+ TData extends RowData,
42
+ TAtomValue,
43
+ > = {
44
+ table: Table<TFeatures, TData>
45
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>
46
+ selector?: undefined
47
+ children: ((state: TAtomValue) => ReactNode) | ReactNode
48
+ }
49
+
50
+ /**
51
+ * Subscribe to a projected value from a slice atom. The selector receives the
52
+ * atom value; children receive the projected `TSelected`.
53
+ */
54
+ export type SubscribePropsWithAtomWithSelector<
55
+ TFeatures extends TableFeatures,
56
+ TData extends RowData,
57
+ TAtomValue,
58
+ TSelected,
59
+ > = {
60
+ table: Table<TFeatures, TData>
61
+ atom: Atom<TAtomValue> | ReadonlyAtom<TAtomValue>
62
+ selector: (state: TAtomValue) => TSelected
63
+ children: ((state: TSelected) => ReactNode) | ReactNode
64
+ }
65
+
66
+ /**
67
+ * Subscribe to a single slice atom (identity or projected). Prefer
68
+ * {@link SubscribePropsWithAtomIdentity} or {@link SubscribePropsWithAtomWithSelector}
69
+ * for clearer inference when `selector` is omitted.
70
+ */
71
+ export type SubscribePropsWithAtom<
72
+ TFeatures extends TableFeatures,
73
+ TData extends RowData,
74
+ TAtomValue,
75
+ TSelected = TAtomValue,
76
+ > =
77
+ | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>
78
+ | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>
79
+
80
+ export type SubscribeProps<
81
+ TFeatures extends TableFeatures,
82
+ TData extends RowData,
83
+ TSelected = unknown,
84
+ TAtomValue = unknown,
85
+ > =
86
+ | SubscribePropsWithStore<TFeatures, TData, TSelected>
87
+ | SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>
88
+ | SubscribePropsWithAtomWithSelector<TFeatures, TData, TAtomValue, TSelected>
89
+
34
90
  /**
35
91
  * A React component that allows you to subscribe to the table state.
36
92
  *
37
93
  * This is useful for opting into state re-renders for specific parts of the table state.
38
94
  *
95
+ * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so JSX
96
+ * contextual typing works. This standalone component uses a union `props` type.
97
+ *
39
98
  * @example
40
99
  * ```tsx
41
- * // As a standalone component
100
+ * // As a standalone component — full store
42
101
  * <Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
43
102
  * {({ rowSelection }) => (
44
103
  * <div>Selected rows: {Object.keys(rowSelection).length}</div>
@@ -48,6 +107,26 @@ export type SubscribeProps<
48
107
  *
49
108
  * @example
50
109
  * ```tsx
110
+ * // Entire slice atom (no selector)
111
+ * <Subscribe table={table} atom={table.atoms.rowSelection}>
112
+ * {(rowSelection) => <div>...</div>}
113
+ * </Subscribe>
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * // Project atom value (e.g. one row’s selection)
119
+ * <Subscribe
120
+ * table={table}
121
+ * atom={table.atoms.rowSelection}
122
+ * selector={(rowSelection) => rowSelection?.[row.id]}
123
+ * >
124
+ * {(selected) => <tr data-selected={!!selected}>...</tr>}
125
+ * </Subscribe>
126
+ * ```
127
+ *
128
+ * @example
129
+ * ```tsx
51
130
  * // As table.Subscribe (table instance method)
52
131
  * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
53
132
  * {({ rowSelection }) => (
@@ -59,15 +138,52 @@ export type SubscribeProps<
59
138
  export function Subscribe<
60
139
  TFeatures extends TableFeatures,
61
140
  TData extends RowData,
62
- TSelected = {},
141
+ TAtomValue,
142
+ >(
143
+ props: SubscribePropsWithAtomIdentity<TFeatures, TData, TAtomValue>,
144
+ ): ReturnType<FunctionComponent>
145
+ export function Subscribe<
146
+ TFeatures extends TableFeatures,
147
+ TData extends RowData,
148
+ TAtomValue,
149
+ TSelected,
150
+ >(
151
+ props: SubscribePropsWithAtomWithSelector<
152
+ TFeatures,
153
+ TData,
154
+ TAtomValue,
155
+ TSelected
156
+ >,
157
+ ): ReturnType<FunctionComponent>
158
+ export function Subscribe<
159
+ TFeatures extends TableFeatures,
160
+ TData extends RowData,
161
+ TSelected,
63
162
  >(
64
- props: SubscribeProps<TFeatures, TData, TSelected>,
163
+ props: SubscribePropsWithStore<TFeatures, TData, TSelected>,
164
+ ): ReturnType<FunctionComponent>
165
+ export function Subscribe<
166
+ TFeatures extends TableFeatures,
167
+ TData extends RowData,
168
+ TSelected,
169
+ TAtomValue,
170
+ >(
171
+ props: SubscribeProps<TFeatures, TData, TSelected, TAtomValue>,
65
172
  ): ReturnType<FunctionComponent> {
66
- const selected = useSelector(props.table.store, props.selector, {
67
- compare: shallow,
68
- })
173
+ const source = 'atom' in props ? props.atom : props.table.store
174
+ const selectFn =
175
+ 'atom' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector
176
+
177
+ const selected = useSelector(
178
+ // Atom and store share the same selection protocol; union args need a widen for TS.
179
+ source,
180
+ selectFn as Parameters<typeof useSelector>[1],
181
+ {
182
+ compare: shallow,
183
+ },
184
+ ) as TSelected
69
185
 
70
186
  return typeof props.children === 'function'
71
- ? props.children(selected)
187
+ ? (props.children as (state: TSelected) => ReactNode)(selected)
72
188
  : props.children
73
189
  }
@@ -0,0 +1 @@
1
+ export * from '@tanstack/table-core/static-functions'