From ffe8f1eeed4464935965ccb85d9dff8436c3b16f Mon Sep 17 00:00:00 2001 From: hemengke <23536175@qq.com> Date: Thu, 6 Jan 2022 14:39:12 +0800 Subject: [PATCH 1/2] fix: header column resize delay --- docs/examples/column-resize.tsx | 1 + src/Body/MeasureRow.tsx | 24 ++++++------------------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/docs/examples/column-resize.tsx b/docs/examples/column-resize.tsx index 06db4f8ce..1bd1a954e 100644 --- a/docs/examples/column-resize.tsx +++ b/docs/examples/column-resize.tsx @@ -31,6 +31,7 @@ interface DemoState { columns: ColumnType[]; } + class Demo extends React.Component<{}, DemoState> { state: DemoState = { columns: [ diff --git a/src/Body/MeasureRow.tsx b/src/Body/MeasureRow.tsx index be468f2ec..c5e21b72c 100644 --- a/src/Body/MeasureRow.tsx +++ b/src/Body/MeasureRow.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import ResizeObserver from 'rc-resize-observer'; import MeasureCell from './MeasureCell'; -import raf from 'rc-util/lib/raf'; export interface MeasureCellProps { prefixCls: string; @@ -12,25 +11,14 @@ export interface MeasureCellProps { export default function MeasureRow({ prefixCls, columnsKey, onColumnResize }: MeasureCellProps) { // delay state update while resize continuously, e.g. window resize const resizedColumnsRef = React.useRef(new Map()); - const rafIdRef = React.useRef(null); - const delayOnColumnResize = () => { - if (rafIdRef.current === null) { - rafIdRef.current = raf(() => { - resizedColumnsRef.current.forEach((width, columnKey) => { - onColumnResize(columnKey, width); - }); - resizedColumnsRef.current.clear(); - rafIdRef.current = null; - }, 2); - } + const batchOnColumnResize = () => { + resizedColumnsRef.current.forEach((width, columnKey) => { + onColumnResize(columnKey, width); + }); + resizedColumnsRef.current.clear(); }; - React.useEffect(() => { - return () => { - raf.cancel(rafIdRef.current); - }; - }, []); return ( { resizedColumnsRef.current.set(columnKey, size.offsetWidth); }); - delayOnColumnResize(); + batchOnColumnResize(); }} > {columnsKey.map(columnKey => ( From b1e92c39a9704f04cc400e56dfe14dfe843efac0 Mon Sep 17 00:00:00 2001 From: hemengke <23536175@qq.com> Date: Mon, 10 Jan 2022 20:52:16 +0800 Subject: [PATCH 2/2] perf: remove useless code --- src/Body/MeasureRow.tsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Body/MeasureRow.tsx b/src/Body/MeasureRow.tsx index c5e21b72c..3dbd12113 100644 --- a/src/Body/MeasureRow.tsx +++ b/src/Body/MeasureRow.tsx @@ -9,16 +9,6 @@ export interface MeasureCellProps { } export default function MeasureRow({ prefixCls, columnsKey, onColumnResize }: MeasureCellProps) { - // delay state update while resize continuously, e.g. window resize - const resizedColumnsRef = React.useRef(new Map()); - - const batchOnColumnResize = () => { - resizedColumnsRef.current.forEach((width, columnKey) => { - onColumnResize(columnKey, width); - }); - resizedColumnsRef.current.clear(); - }; - return ( { infoList.forEach(({ data: columnKey, size }) => { - resizedColumnsRef.current.set(columnKey, size.offsetWidth); + onColumnResize(columnKey, size.offsetWidth); }); - batchOnColumnResize(); }} > {columnsKey.map(columnKey => (