Skip to content

Commit

Permalink
fix(useSize): prevents accessing iframe's property when it's not defined
Browse files Browse the repository at this point in the history
ref #442
  • Loading branch information
ManojBahuguna committed Jul 4, 2019
1 parent cf68e36 commit c9b5cdc
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 c9b5cdc

Please sign in to comment.