@@ -28,11 +28,6 @@ export default function useCelResize(
28
28
'onColumnResizeComplete' ,
29
29
'onResizingChange' ,
30
30
] ) ;
31
- const colsWidthsRef = useRef ( colsWidths ) ;
32
- colsWidthsRef . current = colsWidths ;
33
- const colWidthsRef = useRef ( colWidths ) ;
34
- colWidthsRef . current = colWidths ;
35
-
36
31
const [ isResizing , setIsResizing ] = useState ( false ) ;
37
32
const [ lineLeft , setLineLeft ] = useState ( 0 ) ;
38
33
const lineStartLeftRef = useRef ( 0 ) ;
@@ -50,7 +45,7 @@ export default function useCelResize(
50
45
51
46
const onResize = ( event : MouseEvent , isResizeEnd ?: boolean ) => {
52
47
const offset = event . pageX - startPageX . current ;
53
- const oldWidth = colsWidthsRef . current . get ( columnKey ) ;
48
+ const oldWidth = colsWidths . get ( columnKey ) ;
54
49
let newWidth = startRealWidth . current + ( isFixRight ? - offset : offset ) ;
55
50
56
51
const minWidth = typeof resizable === 'object' ? resizable . minWidth || 0 : 0 ;
@@ -63,7 +58,7 @@ export default function useCelResize(
63
58
) ;
64
59
65
60
if ( isResizeEnd ) {
66
- const totalWidth = colWidthsRef . current . reduce ( ( total , width ) => total + width , 0 ) ;
61
+ const totalWidth = colWidths . reduce ( ( total , width ) => total + width , 0 ) ;
67
62
const smallThanWidth = componentWidth - ( totalWidth - oldWidth + newWidth ) ;
68
63
// If it is less than the width of the table, the remaining width will be allocated to the column on the right.
69
64
// If there is no column on the right, it will be allocated to the column on the left.
@@ -74,11 +69,10 @@ export default function useCelResize(
74
69
addWidthColumnKey = colsKeys [ index + 1 ] ?? colsKeys [ index - 1 ] ;
75
70
}
76
71
77
- const columnKeyWidthsMap = new Map ( colsWidthsRef . current ) ;
72
+ const columnKeyWidthsMap = new Map ( colsWidths ) ;
78
73
columnKeyWidthsMap . set ( columnKey , newWidth ) ;
79
74
if ( addWidthColumnKey ) {
80
- const addWidthColumnNewWidth =
81
- colsWidthsRef . current . get ( addWidthColumnKey ) + ( oldWidth - newWidth ) ;
75
+ const addWidthColumnNewWidth = colsWidths . get ( addWidthColumnKey ) + ( oldWidth - newWidth ) ;
82
76
columnKeyWidthsMap . set ( addWidthColumnKey , addWidthColumnNewWidth ) ;
83
77
}
84
78
const columnKeyWidths = Array . from ( columnKeyWidthsMap ) . map ( ( [ key , width ] ) => ( {
@@ -105,7 +99,7 @@ export default function useCelResize(
105
99
] - fullTableRef . current . getBoundingClientRect ( ) . left ;
106
100
setLineLeft ( left ) ;
107
101
lineStartLeftRef . current = left ;
108
- startRealWidth . current = colsWidthsRef . current . get ( columnKey ) ;
102
+ startRealWidth . current = colsWidths . get ( columnKey ) ;
109
103
startPageX . current = event . pageX ;
110
104
document . body . addEventListener ( 'mousemove' , onResize ) ;
111
105
document . body . addEventListener ( 'mouseup' , onResizeEnd ) ;
0 commit comments