@@ -74,6 +74,18 @@ const EMPTY_SCROLL_TARGET = {};
74
74
75
75
export const INTERNAL_HOOKS = 'rc-table-internal-hook' ;
76
76
77
+ interface MemoTableContentProps {
78
+ children : React . ReactNode ;
79
+ pingLeft : boolean ;
80
+ pingRight : boolean ;
81
+ }
82
+ const MemoTableContent = React . memo < MemoTableContentProps > (
83
+ ( { children } ) => children as React . ReactElement ,
84
+ // No additional render when pinged status change.
85
+ // This is not a bug.
86
+ ( prev , next ) => prev . pingLeft !== next . pingLeft || prev . pingRight !== next . pingRight ,
87
+ ) ;
88
+
77
89
export interface TableProps < RecordType = unknown > extends LegacyExpandableProps < RecordType > {
78
90
prefixCls ?: string ;
79
91
className ?: string ;
@@ -326,10 +338,13 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
326
338
internalHooks === INTERNAL_HOOKS ? transformColumns : null ,
327
339
) ;
328
340
329
- const columnContext = {
330
- columns,
331
- flattenColumns,
332
- } ;
341
+ const columnContext = React . useMemo (
342
+ ( ) => ( {
343
+ columns,
344
+ flattenColumns,
345
+ } ) ,
346
+ [ columns , flattenColumns ] ,
347
+ ) ;
333
348
334
349
// ====================== Scroll ======================
335
350
const fullTableRef = React . useRef < HTMLDivElement > ( ) ;
@@ -371,13 +386,13 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
371
386
} ;
372
387
}
373
388
374
- function onColumnResize ( columnKey : React . Key , width : number ) {
389
+ const onColumnResize = React . useCallback ( ( columnKey : React . Key , width : number ) => {
375
390
updateColsWidths ( widths => {
376
391
const newWidths = new Map ( widths ) ;
377
392
newWidths . set ( columnKey , width ) ;
378
393
return newWidths ;
379
394
} ) ;
380
- }
395
+ } , [ ] ) ;
381
396
382
397
const [ setScrollTarget , getScrollTarget ] = useTimeoutLock ( null ) ;
383
398
@@ -612,44 +627,69 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
612
627
ref = { fullTableRef }
613
628
{ ...ariaProps }
614
629
>
615
- { title && < Panel className = { `${ prefixCls } -title` } > { title ( mergedData ) } </ Panel > }
616
- < div className = { `${ prefixCls } -container` } > { groupTableNode } </ div >
617
- { footer && < Panel className = { `${ prefixCls } -footer` } > { footer ( mergedData ) } </ Panel > }
630
+ < MemoTableContent pingLeft = { pingedLeft } pingRight = { pingedRight } >
631
+ { title && < Panel className = { `${ prefixCls } -title` } > { title ( mergedData ) } </ Panel > }
632
+ < div className = { `${ prefixCls } -container` } > { groupTableNode } </ div >
633
+ { footer && < Panel className = { `${ prefixCls } -footer` } > { footer ( mergedData ) } </ Panel > }
634
+ </ MemoTableContent >
618
635
</ div >
619
636
) ;
620
637
621
638
if ( fixColumn ) {
622
639
fullTable = < ResizeObserver onResize = { onFullTableResize } > { fullTable } </ ResizeObserver > ;
623
640
}
624
641
642
+ const TableContextValue = React . useMemo (
643
+ ( ) => ( {
644
+ prefixCls,
645
+ getComponent,
646
+ scrollbarSize,
647
+ direction,
648
+ } ) ,
649
+ [ prefixCls , getComponent , scrollbarSize , direction ] ,
650
+ ) ;
651
+
652
+ const BodyContextValue = React . useMemo (
653
+ ( ) => ( {
654
+ ...columnContext ,
655
+ tableLayout : mergedTableLayout ,
656
+ rowClassName,
657
+ expandedRowClassName,
658
+ componentWidth,
659
+ fixHeader,
660
+ fixColumn,
661
+ expandIcon : mergedExpandIcon ,
662
+ expandableType,
663
+ expandRowByClick,
664
+ expandedRowRender,
665
+ onTriggerExpand,
666
+ expandIconColumnIndex,
667
+ indentSize,
668
+ } ) ,
669
+ [
670
+ columnContext ,
671
+ mergedTableLayout ,
672
+ rowClassName ,
673
+ expandedRowClassName ,
674
+ componentWidth ,
675
+ fixHeader ,
676
+ fixColumn ,
677
+ mergedExpandIcon ,
678
+ expandableType ,
679
+ expandRowByClick ,
680
+ expandedRowRender ,
681
+ onTriggerExpand ,
682
+ expandIconColumnIndex ,
683
+ indentSize ,
684
+ ] ,
685
+ ) ;
686
+
687
+ const ResizeContextValue = React . useMemo ( ( ) => ( { onColumnResize } ) , [ onColumnResize ] ) ;
688
+
625
689
return (
626
- < TableContext . Provider
627
- value = { {
628
- prefixCls,
629
- getComponent,
630
- scrollbarSize,
631
- direction,
632
- } }
633
- >
634
- < BodyContext . Provider
635
- value = { {
636
- ...columnContext ,
637
- tableLayout : mergedTableLayout ,
638
- rowClassName,
639
- expandedRowClassName,
640
- componentWidth,
641
- fixHeader,
642
- fixColumn,
643
- expandIcon : mergedExpandIcon ,
644
- expandableType,
645
- expandRowByClick,
646
- expandedRowRender,
647
- onTriggerExpand,
648
- expandIconColumnIndex,
649
- indentSize,
650
- } }
651
- >
652
- < ResizeContext . Provider value = { { onColumnResize } } > { fullTable } </ ResizeContext . Provider >
690
+ < TableContext . Provider value = { TableContextValue } >
691
+ < BodyContext . Provider value = { BodyContextValue } >
692
+ < ResizeContext . Provider value = { ResizeContextValue } > { fullTable } </ ResizeContext . Provider >
653
693
</ BodyContext . Provider >
654
694
</ TableContext . Provider >
655
695
) ;
0 commit comments