@@ -81,30 +81,33 @@ function warningFixed(flattenColumns: { fixed?: FixedType }[]) {
8181/**
8282 * Parse `columns` & `children` into `columns`.
8383 */
84- function useColumns < RecordType > ( {
85- prefixCls,
86- columns,
87- children,
88- expandable,
89- expandedKeys,
90- getRowKey,
91- onTriggerExpand,
92- expandIcon,
93- rowExpandable,
94- expandIconColumnIndex,
95- } : {
96- prefixCls ?: string ;
97- columns ?: ColumnsType < RecordType > ;
98- children ?: React . ReactNode ;
99- expandable : boolean ;
100- expandedKeys : Set < Key > ;
101- getRowKey : GetRowKey < RecordType > ;
102- onTriggerExpand : TriggerEventHandler < RecordType > ;
103- expandIcon ?: RenderExpandIcon < RecordType > ;
104- rowExpandable ?: ( record : RecordType ) => boolean ;
105- expandIconColumnIndex ?: number ;
106- } ) : [ ColumnsType < RecordType > , ColumnType < RecordType > [ ] ] {
107- const mergedColumns = React . useMemo < ColumnsType < RecordType > > (
84+ function useColumns < RecordType > (
85+ {
86+ prefixCls,
87+ columns,
88+ children,
89+ expandable,
90+ expandedKeys,
91+ getRowKey,
92+ onTriggerExpand,
93+ expandIcon,
94+ rowExpandable,
95+ expandIconColumnIndex,
96+ } : {
97+ prefixCls ?: string ;
98+ columns ?: ColumnsType < RecordType > ;
99+ children ?: React . ReactNode ;
100+ expandable : boolean ;
101+ expandedKeys : Set < Key > ;
102+ getRowKey : GetRowKey < RecordType > ;
103+ onTriggerExpand : TriggerEventHandler < RecordType > ;
104+ expandIcon ?: RenderExpandIcon < RecordType > ;
105+ rowExpandable ?: ( record : RecordType ) => boolean ;
106+ expandIconColumnIndex ?: number ;
107+ } ,
108+ transformColumns : ( columns : ColumnsType < RecordType > ) => ColumnsType < RecordType > ,
109+ ) : [ ColumnsType < RecordType > , ColumnType < RecordType > [ ] ] {
110+ const baseColumns = React . useMemo < ColumnsType < RecordType > > (
108111 ( ) => columns || convertChildrenToColumns ( children ) ,
109112 [ columns , children ] ,
110113 ) ;
@@ -113,7 +116,7 @@ function useColumns<RecordType>({
113116 const withExpandColumns = React . useMemo < ColumnsType < RecordType > > ( ( ) => {
114117 if ( expandable ) {
115118 const expandColIndex = expandIconColumnIndex || 0 ;
116- const prevColumn = mergedColumns [ expandColIndex ] ;
119+ const prevColumn = baseColumns [ expandColIndex ] ;
117120
118121 const expandColumn = {
119122 [ INTERNAL_COL_DEFINE ] : {
@@ -138,22 +141,27 @@ function useColumns<RecordType>({
138141 } ;
139142
140143 // Insert expand column in the target position
141- const cloneColumns = mergedColumns . slice ( ) ;
144+ const cloneColumns = baseColumns . slice ( ) ;
142145 cloneColumns . splice ( expandColIndex , 0 , expandColumn ) ;
143146
144147 return cloneColumns ;
145148 }
146- return mergedColumns ;
147- } , [ expandable , mergedColumns , getRowKey , expandedKeys , expandIcon ] ) ;
149+ return baseColumns ;
150+ } , [ expandable , baseColumns , getRowKey , expandedKeys , expandIcon ] ) ;
148151
149- const flattenColumns = React . useMemo ( ( ) => flatColumns ( withExpandColumns ) , [ withExpandColumns ] ) ;
152+ const mergedColumns = React . useMemo (
153+ ( ) => ( transformColumns ? transformColumns ( withExpandColumns ) : withExpandColumns ) ,
154+ [ transformColumns , withExpandColumns ] ,
155+ ) ;
156+
157+ const flattenColumns = React . useMemo ( ( ) => flatColumns ( mergedColumns ) , [ mergedColumns ] ) ;
150158
151159 // Only check out of production since it's waste for each render
152160 if ( process . env . NODE_ENV !== 'production' ) {
153161 warningFixed ( flattenColumns ) ;
154162 }
155163
156- return [ withExpandColumns , flattenColumns ] ;
164+ return [ mergedColumns , flattenColumns ] ;
157165}
158166
159167export default useColumns ;
0 commit comments