diff --git a/packages/react-table/src/Subscribe.ts b/packages/react-table/src/Subscribe.ts index 3a378b25a3..5b1e24212d 100644 --- a/packages/react-table/src/Subscribe.ts +++ b/packages/react-table/src/Subscribe.ts @@ -1,6 +1,6 @@ 'use client' -import { useStore } from '@tanstack/react-store' +import { shallow, useStore } from '@tanstack/react-store' import type { NoInfer, RowData, @@ -63,7 +63,7 @@ export function Subscribe< >( props: SubscribeProps, ): ReturnType { - const selected = useStore(props.table.store, props.selector) + const selected = useStore(props.table.store, props.selector, shallow) return typeof props.children === 'function' ? props.children(selected) diff --git a/packages/react-table/src/useLegacyTable.ts b/packages/react-table/src/useLegacyTable.ts index f6fb7e1c44..ff428e021a 100644 --- a/packages/react-table/src/useLegacyTable.ts +++ b/packages/react-table/src/useLegacyTable.ts @@ -15,8 +15,8 @@ import { sortFns, stockFeatures, } from '@tanstack/table-core' -import { useMemo } from 'react' -import { useStore } from '@tanstack/react-store' +import { useCallback, useMemo } from 'react' +import { shallow, useStore } from '@tanstack/react-store' import { useTable } from './useTable' import type { Cell, @@ -419,20 +419,21 @@ export function useLegacyTable( } // Call useTable with the v9 API, subscribing to all state changes - const table = useTable>({ - ...restOptions, - _features: stockFeatures, - _rowModels, - } as TableOptions) - - const state = useStore(table.store, (state) => state) + const table = useTable>( + { + ...restOptions, + _features: stockFeatures, + _rowModels, + } as TableOptions, + (state) => state, + ) return useMemo( () => ({ ...table, - getState: () => state, + getState: () => table.state, }) as LegacyReactTable, - [table, state], + [table], ) }