import * as React from 'react'; import type { ColumnsType, ColumnTitleProps, TransformColumns } from '../interface'; import { renderColumnTitle } from '../util'; function fillTitle( columns: ColumnsType, columnTitleProps: ColumnTitleProps, ) { return columns.map(column => { const cloneColumn = { ...column }; cloneColumn.title = renderColumnTitle(column.title, columnTitleProps); if ('children' in cloneColumn) { cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps); } return cloneColumn; }); } export default function useTitleColumns( columnTitleProps: ColumnTitleProps, ): [TransformColumns] { const filledColumns = React.useCallback( (columns: ColumnsType) => fillTitle(columns, columnTitleProps), [columnTitleProps], ); return [filledColumns]; }