Skip to content

Commit

Permalink
fix(useSize): prevents accessing iframe's property when it's not… (#443)
Browse files Browse the repository at this point in the history
fix(useSize): prevents accessing iframe's property when it's not defined
  • Loading branch information
streamich authored Jul 4, 2019
2 parents cf68e36 + c9b5cdc commit 8f04e8f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/useSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8f04e8f

Please sign in to comment.