diff --git a/examples/scrollX.tsx b/examples/scrollX.tsx index e5036a0df..7eb3c555f 100644 --- a/examples/scrollX.tsx +++ b/examples/scrollX.tsx @@ -3,7 +3,12 @@ import Table from '../src'; import '../assets/index.less'; const columns = [ - { title: 'title1', dataIndex: 'a', key: 'a', width: 100 }, + { + title: 'title1', + dataIndex: 'a', + key: 'a', + width: 100, + }, { title: 'title2', dataIndex: 'b', key: 'b', width: 100 }, { title: 'title3', dataIndex: 'c', key: 'c', width: 100 }, { title: 'title4', dataIndex: 'b', key: 'd', width: 100 }, @@ -27,7 +32,7 @@ const data = [ const Demo = () => (

Scroll X

- +
); diff --git a/package.json b/package.json index 2e73bef84..5274eaa0b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "prop-types": "^15.5.8", "raf": "^3.4.1", "rc-resize-observer": "^0.1.2", - "rc-util": "^4.19.0", + "rc-util": "^4.20.1", "react-lifecycles-compat": "^3.0.2", "shallowequal": "^1.1.0" }, diff --git a/src/Table.tsx b/src/Table.tsx index 105178ced..53a7ab595 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -74,6 +74,18 @@ const EMPTY_SCROLL_TARGET = {}; export const INTERNAL_HOOKS = 'rc-table-internal-hook'; +interface MemoTableContentProps { + children: React.ReactNode; + pingLeft: boolean; + pingRight: boolean; +} +const MemoTableContent = React.memo( + ({ children }) => children as React.ReactElement, + // No additional render when pinged status change. + // This is not a bug. + (prev, next) => prev.pingLeft !== next.pingLeft || prev.pingRight !== next.pingRight, +); + export interface TableProps extends LegacyExpandableProps { prefixCls?: string; className?: string; @@ -326,10 +338,13 @@ function Table(props: TableProps ({ + columns, + flattenColumns, + }), + [columns, flattenColumns], + ); // ====================== Scroll ====================== const fullTableRef = React.useRef(); @@ -371,13 +386,13 @@ function Table(props: TableProps { updateColsWidths(widths => { const newWidths = new Map(widths); newWidths.set(columnKey, width); return newWidths; }); - } + }, []); const [setScrollTarget, getScrollTarget] = useTimeoutLock(null); @@ -612,9 +627,11 @@ function Table(props: TableProps - {title && {title(mergedData)}} -
{groupTableNode}
- {footer && {footer(mergedData)}} + + {title && {title(mergedData)}} +
{groupTableNode}
+ {footer && {footer(mergedData)}} +
); @@ -622,34 +639,57 @@ function Table(props: TableProps{fullTable}; } + const TableContextValue = React.useMemo( + () => ({ + prefixCls, + getComponent, + scrollbarSize, + direction, + }), + [prefixCls, getComponent, scrollbarSize, direction], + ); + + const BodyContextValue = React.useMemo( + () => ({ + ...columnContext, + tableLayout: mergedTableLayout, + rowClassName, + expandedRowClassName, + componentWidth, + fixHeader, + fixColumn, + expandIcon: mergedExpandIcon, + expandableType, + expandRowByClick, + expandedRowRender, + onTriggerExpand, + expandIconColumnIndex, + indentSize, + }), + [ + columnContext, + mergedTableLayout, + rowClassName, + expandedRowClassName, + componentWidth, + fixHeader, + fixColumn, + mergedExpandIcon, + expandableType, + expandRowByClick, + expandedRowRender, + onTriggerExpand, + expandIconColumnIndex, + indentSize, + ], + ); + + const ResizeContextValue = React.useMemo(() => ({ onColumnResize }), [onColumnResize]); + return ( - - - {fullTable} + + + {fullTable} );