To access the table state or methods in child components, use the useTableContext hook provided by your factory. For this to work, the child components must be wrapped in the corresponding provider (e.g., table.AppTable).
AppTable can be used in two ways:
- Standard usage: Pass ordinary JSX children. The children will have access to the table context.
- Selector usage: Pass a
selector function and a function as children. The function child will receive the specific slice of state returned by the selector.
// 1. Standard usage with useTableContext
function RowCount() {
const table = useTableContext()
return <output>{table.getRowModel().rows.length}</output>
}
function MyTable({ data, columns }) {
const table = useAppTable({ data, columns })
return (
<table.AppTable>
<RowCount />
</table.AppTable>
)
}
// 2. Selector usage for specific state slices
<table.AppTable selector={(state) => state.rowSelection}>
{(rowSelection) => <output>{Object.keys(rowSelection).length}</output>}
</table.AppTable>