This repository was archived by the owner on Dec 26, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-35
lines changed
Expand file tree Collapse file tree 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 {
1111 width : 1 ,
1212 height : 1
1313 } ;
14+
15+ this . ref = React . createRef ( ) ;
1416 }
1517
1618 observeIfNeeded ( ) {
17- const element = this . props . element || ReactDOM . findDOMNode ( this ) ;
19+ const element = this . ref . current ;
1820
1921 if ( element && this . element !== element ) {
2022 // clean up after a previous element
@@ -66,18 +68,12 @@ class ResizeObserverComponent extends Component {
6668 }
6769
6870 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 ) ;
7572 }
7673}
7774
7875ResizeObserverComponent . propTypes = {
79- children : PropTypes . func . isRequired ,
80- element : PropTypes . object
76+ children : PropTypes . func . isRequired
8177} ;
8278
8379export default ResizeObserverComponent ;
Original file line number Diff line number Diff line change @@ -8,33 +8,11 @@ import delay from "delay";
88// works while it might actually not, if you use the lib without babel-polyfill.
99import "babel-regenerator-runtime" ;
1010
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-
3411const Observed = ( ) => (
3512 < ResizeObserver >
36- { ( { width, height } ) => (
13+ { ( ref , width , height ) => (
3714 < div
15+ ref = { ref }
3816 id = "observed"
3917 style = { {
4018 position : "absolute" ,
@@ -66,8 +44,6 @@ beforeAll(() => {
6644 global . observed = document . querySelector ( "#observed" ) ;
6745} ) ;
6846
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
7147it ( "should render with 1x1 initially, before the ResizeObserver is triggered" , async ( ) => {
7248 expect ( observed . textContent ) . toBe ( "1x1" ) ;
7349} ) ;
You can’t perform that action at this time.
0 commit comments