From c9b5cdca4290ebf58e620fe2af6e99fcd8e93b37 Mon Sep 17 00:00:00 2001 From: Manoj Bahuguna Date: Thu, 4 Jul 2019 18:04:51 +0000 Subject: [PATCH] fix(useSize): prevents accessing iframe's property when it's not defined ref #442 --- src/useSize.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/useSize.tsx b/src/useSize.tsx index 797bd08482..c488e76718 100644 --- a/src/useSize.tsx +++ b/src/useSize.tsx @@ -45,7 +45,13 @@ const useSize = ( }; useEffect(() => { - const iframe: HTMLIFrameElement = ref.current!; + const iframe: HTMLIFrameElement = ref.current; + + if(!iframe) { + // iframe will be undefined if component is already unmounted + return; + } + if (iframe.contentWindow) { window = iframe.contentWindow!; onWindow(window);