File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,12 @@ export default function useHyperResponsive(ref) {
8
8
height : 0
9
9
} )
10
10
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 ( ( ) => {
14
17
if ( ! ref . current ) {
15
18
return
16
19
}
@@ -46,20 +49,20 @@ export default function useHyperResponsive(ref) {
46
49
newHeight -= parseInt ( borderBottomWidth )
47
50
}
48
51
49
- if ( newWidth !== width || newHeight !== height ) {
52
+ if ( newWidth !== dimsRef . current . width || newHeight !== dimsRef . current . height ) {
50
53
setState ( ( ) => ( {
51
54
width : newWidth ,
52
55
height : newHeight
53
56
} ) )
54
57
}
55
- }
58
+ } , [ ref ] )
56
59
57
60
React . useEffect ( ( ) => {
58
- const stopListening = onResize ( ref . current . parentElement , resize . current )
61
+ const stopListening = onResize ( ref . current . parentElement , resize )
59
62
return ( ) => {
60
63
stopListening ( )
61
64
}
62
- } , [ ref ] )
65
+ } , [ ref , resize ] )
63
66
64
67
return [ { width, height } ]
65
68
}
You can’t perform that action at this time.
0 commit comments