Skip to content

Commit 6d14122

Browse files
authored
fix: header column resize delay (#731)
* fix: header column resize delay * perf: remove useless code
1 parent 4cba6e6 commit 6d14122

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

docs/examples/column-resize.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface DemoState {
3131
columns: ColumnType<RecordType>[];
3232
}
3333

34+
3435
class Demo extends React.Component<{}, DemoState> {
3536
state: DemoState = {
3637
columns: [

src/Body/MeasureRow.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import ResizeObserver from 'rc-resize-observer';
33
import MeasureCell from './MeasureCell';
4-
import raf from 'rc-util/lib/raf';
54

65
export interface MeasureCellProps {
76
prefixCls: string;
@@ -10,27 +9,6 @@ export interface MeasureCellProps {
109
}
1110

1211
export default function MeasureRow({ prefixCls, columnsKey, onColumnResize }: MeasureCellProps) {
13-
// delay state update while resize continuously, e.g. window resize
14-
const resizedColumnsRef = React.useRef(new Map());
15-
const rafIdRef = React.useRef(null);
16-
17-
const delayOnColumnResize = () => {
18-
if (rafIdRef.current === null) {
19-
rafIdRef.current = raf(() => {
20-
resizedColumnsRef.current.forEach((width, columnKey) => {
21-
onColumnResize(columnKey, width);
22-
});
23-
resizedColumnsRef.current.clear();
24-
rafIdRef.current = null;
25-
}, 2);
26-
}
27-
};
28-
29-
React.useEffect(() => {
30-
return () => {
31-
raf.cancel(rafIdRef.current);
32-
};
33-
}, []);
3412
return (
3513
<tr
3614
aria-hidden="true"
@@ -40,9 +18,8 @@ export default function MeasureRow({ prefixCls, columnsKey, onColumnResize }: Me
4018
<ResizeObserver.Collection
4119
onBatchResize={infoList => {
4220
infoList.forEach(({ data: columnKey, size }) => {
43-
resizedColumnsRef.current.set(columnKey, size.offsetWidth);
21+
onColumnResize(columnKey, size.offsetWidth);
4422
});
45-
delayOnColumnResize();
4623
}}
4724
>
4825
{columnsKey.map(columnKey => (

0 commit comments

Comments
 (0)