import React from 'react' ; import { ColumnOriginType } from '../useAntdResizableHeader' ; export const GETKEY = 'dataIndex' ; export const ResizableUniqIdPrefix = 'resizable-table-id' ; export function getUniqueId ( index ) { return `${ ResizableUniqIdPrefix }-${ index }` ; } function getColumns < T extends ColumnOriginType < T > > ( list ) { const trulyColumns = list ; const c = trulyColumns ?. map ( ( col , index ) => { return { ... col , children : col ?. children ?. length ? getColumns ( col . children ) : undefined , [ GETKEY ] : col [ GETKEY ] || col . key || getUniqueId ( index ) , } ; } ) ; return c ; } export function useGetDataIndexColumns < T extends ColumnOriginType < T > > ( columns ) { const dataIndexColumns = React . useMemo ( ( ) => getColumns ( columns ) , [ columns ] ) as T [ ] | undefined ; return dataIndexColumns || columns ; }