Back to Table

Subscribe

docs/framework/react/reference/index/functions/Subscribe.md

8.21.31.2 KB
Original Source

Function: Subscribe()

ts
function Subscribe<TFeatures, TData, TSelected>(props): ReactNode | Promise<ReactNode>;

Defined in: Subscribe.ts:58

A React component that allows you to subscribe to the table state.

This is useful for opting into state re-renders for specific parts of the table state.

Type Parameters

TFeatures

TFeatures extends TableFeatures

TData

TData extends RowData

TSelected

TSelected = { }

Parameters

props

SubscribeProps<TFeatures, TData, TSelected>

Returns

ReactNode | Promise<ReactNode>

Examples

tsx
// As a standalone component
<Subscribe table={table} selector={(state) => ({ rowSelection: state.rowSelection })}>
  {({ rowSelection }) => (
    <div>Selected rows: {Object.keys(rowSelection).length}</div>
  )}
</Subscribe>
tsx
// As table.Subscribe (table instance method)
<table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
  {({ rowSelection }) => (
    <div>Selected rows: {Object.keys(rowSelection).length}</div>
  )}
</table.Subscribe>