File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import useChartState from '../hooks/useChartState'
3
3
import useIsomorphicLayoutEffect from '../hooks/useIsomorphicLayoutEffect'
4
- import { round } from '../utils/Utils'
5
4
6
5
const getElBox = el => {
7
6
var rect = el . getBoundingClientRect ( )
@@ -218,7 +217,7 @@ export default function useMeasure({
218
217
] )
219
218
220
219
// Measure after if needed
221
- React . useEffect ( ( ) => {
220
+ useIsomorphicLayoutEffect ( ( ) => {
222
221
measureDimensions ( )
223
- } , [ measureDimensions ] )
222
+ } )
224
223
}
Original file line number Diff line number Diff line change @@ -6,9 +6,18 @@ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'
6
6
7
7
export default function useRect ( nodeRef ) {
8
8
const [ element , setElement ] = React . useState ( nodeRef . current ?. parentElement )
9
- const [ rect , setRect ] = React . useState ( { width : 0 , height : 0 } )
9
+ const [ rect , _setRect ] = React . useState ( { width : 0 , height : 0 } )
10
10
const initialRectSet = React . useRef ( false )
11
11
12
+ const setRect = React . useCallback ( value => {
13
+ _setRect ( old => {
14
+ if ( old . width !== value . width || old . height !== value . height ) {
15
+ return value
16
+ }
17
+ return old
18
+ } )
19
+ } , [ ] )
20
+
12
21
useIsomorphicLayoutEffect ( ( ) => {
13
22
if ( nodeRef . current ?. parentElement !== element ) {
14
23
setElement ( nodeRef . current ?. parentElement )
@@ -34,7 +43,7 @@ export default function useRect(nodeRef) {
34
43
return ( ) => {
35
44
observer . unobserve ( )
36
45
}
37
- } , [ element ] )
46
+ } , [ element , setRect ] )
38
47
39
48
return { width : rect . width , height : rect . height }
40
49
}
You can’t perform that action at this time.
0 commit comments