Skip to content

Commit ce78bac

Browse files
committed
fix: no rect render on scroll, more frequent axis measuring
1 parent 14f06c5 commit ce78bac

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/components/AxisLinear.useMeasure.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import useChartState from '../hooks/useChartState'
33
import useIsomorphicLayoutEffect from '../hooks/useIsomorphicLayoutEffect'
4-
import { round } from '../utils/Utils'
54

65
const 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
}

src/hooks/useHyperResponsive.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'
66

77
export 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
}

0 commit comments

Comments
 (0)