File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 11'use strict'
2- var React = require ( 'react' )
3- var useState = React . useState
4- var useCallback = React . useCallback
5- var useLayoutEffect = React . useLayoutEffect
2+ const React = require ( 'react' )
3+ const useState = React . useState
4+ const useCallback = React . useCallback
5+ const useLayoutEffect = React . useLayoutEffect
66
77function getSize ( el ) {
88 if ( ! el ) {
@@ -19,14 +19,18 @@ function getSize(el) {
1919}
2020
2121function useComponentSize ( ref ) {
22- var _useState = useState ( getSize ( ref ? ref . current : { } ) )
23- var ComponentSize = _useState [ 0 ]
24- var setComponentSize = _useState [ 1 ]
22+ const _useState = useState ( getSize ( ref ? ref . current : { } ) )
23+ const ComponentSize = _useState [ 0 ]
24+ const setComponentSize = _useState [ 1 ]
2525
26- var handleResize = useCallback (
26+ const handleResize = useCallback (
2727 function handleResize ( ) {
2828 if ( ref . current ) {
29- setComponentSize ( getSize ( ref . current ) )
29+ const newSize = getSize ( ref . current )
30+
31+ if ( ComponentSize . width !== newSize . width && ComponentSize . height !== newSize . height ) {
32+ setComponentSize ( newSize )
33+ }
3034 }
3135 } ,
3236 [ ref ]
You can’t perform that action at this time.
0 commit comments