fix(useSize): prevents accessing iframe's property when it's not… (#443)

fix(useSize): prevents accessing iframe's property when it's not defined
This commit is contained in:
Vadim Dalecky 2019-07-05 00:59:49 +02:00 committed by GitHub
commit 8f04e8fd5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);