Skip to content

Commit 194c8b1

Browse files
committed
Update useHyperResponsive.js
1 parent 15c9e47 commit 194c8b1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/hooks/useHyperResponsive.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ export default function useHyperResponsive(ref) {
88
height: 0
99
})
1010

11-
const resize = React.useRef()
12-
13-
resize.current = () => {
11+
const dimsRef = React.useRef()
12+
dimsRef.current = {
13+
width, height
14+
}
15+
16+
const resize = React.useCallback(() => {
1417
if (!ref.current) {
1518
return
1619
}
@@ -46,20 +49,20 @@ export default function useHyperResponsive(ref) {
4649
newHeight -= parseInt(borderBottomWidth)
4750
}
4851

49-
if (newWidth !== width || newHeight !== height) {
52+
if (newWidth !== dimsRef.current.width || newHeight !== dimsRef.current.height) {
5053
setState(() => ({
5154
width: newWidth,
5255
height: newHeight
5356
}))
5457
}
55-
}
58+
}, [ref])
5659

5760
React.useEffect(() => {
58-
const stopListening = onResize(ref.current.parentElement, resize.current)
61+
const stopListening = onResize(ref.current.parentElement, resize)
5962
return () => {
6063
stopListening()
6164
}
62-
}, [ref])
65+
}, [ref, resize])
6366

6467
return [{ width, height }]
6568
}

0 commit comments

Comments
 (0)