File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,20 @@ import * as React from 'react';
55// to a target HTMLObjectElement or HTMLIFrameElement
66// The real Hook is `useResizeAware.js`
77export default ( ref : React . ElementRef < any > , onResize : ( ) => void ) => {
8- React . useEffect ( ( ) => {
9- const target = ref . current && ref . current . contentDocument && ref . current . contentDocument . defaultView ;
10-
8+ const getTarget = ( ) => ref . current && ref . current . contentDocument && ref . current . contentDocument . defaultView ;
9+ function run ( ) {
1110 // trigger onResize event on mount to provide initial sizes
1211 onResize ( ) ;
13-
12+ var target = getTarget ( ) ;
1413 target && target . addEventListener ( 'resize' , onResize ) ;
14+ }
15+ React . useEffect ( ( ) => {
16+ if ( getTarget ( ) ) {
17+ run ( ) ;
18+ }
19+ else if ( ref . current && ref . current . addEventListener ) {
20+ ref . current . addEventListener ( 'load' , run )
21+ }
1522
1623 // clean event listener on unmount
1724 return ( ) => {
You can’t perform that action at this time.
0 commit comments