useTableColumnResizeState

Provides column width state management for a table component with column resizing support. Handles building a map of column widths calculated from the table's width and any provided column width information from the collection. In addition, it tracks the the currently resizing column and provides callback for updating the widths upon resize operations.

installyarn add react-stately
version3.20.0
usageimport {useTableColumnResizeState} from 'react-stately'

API#


useTableColumnResizeState<T>( (props: TableColumnResizeStateProps<T>, , state: TableState<T> )): TableColumnResizeState<T>

Interface#


NameTypeDescription
onColumnResize( (key: Key, , width: number )) => Map<Key, ColumnSize>

Called to update the state that a resize event has occurred. Returns the new widths for all columns based on the resized column. *

onColumnResizeStart( (key: Key )) => voidCallback for when onColumnResize has started.
onColumnResizeEnd() => voidCallback for when onColumnResize has ended.
getColumnWidth( (key: Key )) => numberGets the current width for the specified column.
getColumnMinWidth( (key: Key )) => numberGets the current minWidth for the specified column.
getColumnMaxWidth( (key: Key )) => numberGets the current maxWidth for the specified column.
widthsMap<Key, number>Currently calculated widths for all columns.
resizingColumnKeynullKey of the currently resizing column.
tableStateTableState<T>A reference to the table state.

Example#


See the docs for useTable in react-aria for an example of using useTableColumnResizeState with useTableState to create a table with resizable columns.