This repository was archived by the owner on Dec 26, 2022. It is now read-only.
File tree 2 files changed +7
-35
lines changed
2 files changed +7
-35
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,12 @@ class ResizeObserverComponent extends Component {
11
11
width : 1 ,
12
12
height : 1
13
13
} ;
14
+
15
+ this . ref = React . createRef ( ) ;
14
16
}
15
17
16
18
observeIfNeeded ( ) {
17
- const element = this . props . element || ReactDOM . findDOMNode ( this ) ;
19
+ const element = this . ref . current ;
18
20
19
21
if ( element && this . element !== element ) {
20
22
// clean up after a previous element
@@ -66,18 +68,12 @@ class ResizeObserverComponent extends Component {
66
68
}
67
69
68
70
render ( ) {
69
- const size = {
70
- width : this . state . width ,
71
- height : this . state . height
72
- } ;
73
-
74
- return this . props . children ( size ) ;
71
+ return this . props . children ( this . ref , this . state . width , this . state . height ) ;
75
72
}
76
73
}
77
74
78
75
ResizeObserverComponent . propTypes = {
79
- children : PropTypes . func . isRequired ,
80
- element : PropTypes . object
76
+ children : PropTypes . func . isRequired
81
77
} ;
82
78
83
79
export default ResizeObserverComponent ;
Original file line number Diff line number Diff line change @@ -8,33 +8,11 @@ import delay from "delay";
8
8
// works while it might actually not, if you use the lib without babel-polyfill.
9
9
import "babel-regenerator-runtime" ;
10
10
11
- // const Observed = () => (
12
- // <ResizeObserver>
13
- // {(ref, width, height) => (
14
- // <div
15
- // ref={ref}
16
- // id="observed"
17
- // style={{
18
- // position: "absolute",
19
- // left: 0,
20
- // top: 0,
21
- // width: "100%",
22
- // height: "100%",
23
- // background: "grey",
24
- // color: "white",
25
- // fontWeight: "bold"
26
- // }}
27
- // >
28
- // {width}x{height}
29
- // </div>
30
- // )}
31
- // </ResizeObserver>
32
- // );
33
-
34
11
const Observed = ( ) => (
35
12
< ResizeObserver >
36
- { ( { width, height } ) => (
13
+ { ( ref , width , height ) => (
37
14
< div
15
+ ref = { ref }
38
16
id = "observed"
39
17
style = { {
40
18
position : "absolute" ,
@@ -66,8 +44,6 @@ beforeAll(() => {
66
44
global . observed = document . querySelector ( "#observed" ) ;
67
45
} ) ;
68
46
69
- // todo make sure parcel transpiles down to IE10 (example: async and "Set" doesn't work properly)
70
- // todo run in sauce labs with multiple browsers
71
47
it ( "should render with 1x1 initially, before the ResizeObserver is triggered" , async ( ) => {
72
48
expect ( observed . textContent ) . toBe ( "1x1" ) ;
73
49
} ) ;
You can’t perform that action at this time.
0 commit comments