import { TableOptions, TableState } from "@tanstack/react-table"; export interface TableOptionsProps extends Omit, "getCoreRowModel"> { onTableStateChange?: (state: Partial | null) => void; } /** * Hook for managing and controlling a table's state and behavior. * * Wraps `@tanstack/react-table` with built-in state management for column visibility, * ordering, sorting, sizing, and pinning. Reads `meta.hiddenByDefault` and `meta.pinned` * from column definitions so the table is correctly configured from a single source of truth. * * **When to use:** * - Use `useTable` whenever you render a `` component — it is the standard way to * initialise and manage table state in this codebase. * - Use `useTableSelection` on top of `useTable` when you need row selection checkboxes. * - Do **not** call `useReactTable` directly — `useTable` adds required column-state * orchestration that the raw hook does not provide. * * Row expansion is managed like the column state: it starts from `initialState.expanded`, and * expand/collapse changes are reported to `onTableStateChange` so they can be persisted — unless * the consumer passes `state.expanded`, in which case it owns what is worth storing. * * `onTableStateChange` is called with the field that changed, not the whole state, so anything * storing it has to merge each report into what it already holds. `useTablePersistence` does. * * @template TData - The type representing the data model associated with the table. * @param {TableOptionsProps} props - The props object containing configuration options. * @returns {object} An object containing the React Table instance and associated state management functions. * @example * ```tsx * import { createColumnHelper } from "@tanstack/react-table"; * import { Table, useTable } from "@trackunit/react-table"; * * const columnHelper = createColumnHelper(); * * const columns = [ * columnHelper.accessor("name", { header: "Name" }), * columnHelper.accessor("brand", { header: "Brand" }), * columnHelper.accessor("hours", { * header: "Hours", * meta: { hiddenByDefault: true }, * }), * ]; * * const AssetsTable = ({ data }: { data: Asset[] }) => { * const { table } = useTable({ * data, * columns, * initialState: { sorting: [{ id: "name", desc: false }] }, * onTableStateChange: changedField => setPreferences(previous => ({ ...previous, ...changedField })), * }); * * return
; * }; * ``` */ export declare const useTable: ({ onTableStateChange, initialState, columns, ...reactTableProps }: TableOptionsProps) => { table: import("@tanstack/react-table").Table; };