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';
5
5
// to a target HTMLObjectElement or HTMLIFrameElement
6
6
// The real Hook is `useResizeAware.js`
7
7
export 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 ( ) {
11
10
// trigger onResize event on mount to provide initial sizes
12
11
onResize ( ) ;
13
-
12
+ var target = getTarget ( ) ;
14
13
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
+ }
15
22
16
23
// clean event listener on unmount
17
24
return ( ) => {
You can’t perform that action at this time.
0 commit comments