Skip to content

Commit 43046d8

Browse files
fix: change return value of useEffect to fix critical issue
1 parent 62e5f14 commit 43046d8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/useComponentSize.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function useComponentSize() {
66
height: 0,
77
width: 0,
88
});
9-
const ref = React.useRef<HTMLElement>();
9+
const ref = React.useRef<any>();
1010

1111
const onResize = React.useCallback(() => {
1212
if (!ref.current) {
@@ -25,15 +25,15 @@ export function useComponentSize() {
2525
}, [size.height, size.width]);
2626

2727
React.useLayoutEffect(() => {
28-
if (!ref.current) {
28+
if (!ref || !ref.current) {
2929
return;
3030
}
3131

3232
const resizeObserver = new ResizeObserver(onResize);
3333
resizeObserver.observe(ref.current);
3434

35-
return resizeObserver.disconnect;
36-
}, [onResize]);
35+
return () => resizeObserver.disconnect();
36+
}, [ref, onResize]);
3737

3838
return {
3939
ref,

0 commit comments

Comments
 (0)