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 11import React from 'react'
22import useChartState from '../hooks/useChartState'
33import useIsomorphicLayoutEffect from '../hooks/useIsomorphicLayoutEffect'
4- import { round } from '../utils/Utils'
54
65const getElBox = el => {
76 var rect = el . getBoundingClientRect ( )
@@ -218,7 +217,7 @@ export default function useMeasure({
218217 ] )
219218
220219 // Measure after if needed
221- React . useEffect ( ( ) => {
220+ useIsomorphicLayoutEffect ( ( ) => {
222221 measureDimensions ( )
223- } , [ measureDimensions ] )
222+ } )
224223}
Original file line number Diff line number Diff line change @@ -6,9 +6,18 @@ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'
66
77export default function useRect ( nodeRef ) {
88 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 } )
1010 const initialRectSet = React . useRef ( false )
1111
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+
1221 useIsomorphicLayoutEffect ( ( ) => {
1322 if ( nodeRef . current ?. parentElement !== element ) {
1423 setElement ( nodeRef . current ?. parentElement )
@@ -34,7 +43,7 @@ export default function useRect(nodeRef) {
3443 return ( ) => {
3544 observer . unobserve ( )
3645 }
37- } , [ element ] )
46+ } , [ element , setRect ] )
3847
3948 return { width : rect . width , height : rect . height }
4049}
You can’t perform that action at this time.
0 commit comments