import * as React from 'react'; import { TransformColumns, ColumnTitleProps, ColumnsType } 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]; }