Skip to content

Commit 8f04e8f

Browse files
authored
fix(useSize): prevents accessing iframe's property when it's not… (#443)
fix(useSize): prevents accessing iframe's property when it's not defined
2 parents cf68e36 + c9b5cdc commit 8f04e8f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/useSize.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ const useSize = (
4545
};
4646

4747
useEffect(() => {
48-
const iframe: HTMLIFrameElement = ref.current!;
48+
const iframe: HTMLIFrameElement = ref.current;
49+
50+
if(!iframe) {
51+
// iframe will be undefined if component is already unmounted
52+
return;
53+
}
54+
4955
if (iframe.contentWindow) {
5056
window = iframe.contentWindow!;
5157
onWindow(window);

0 commit comments

Comments
 (0)