-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.jsx
52 lines (44 loc) · 1.23 KB
/
example.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'
import MeasureIt from './index.jsx'
function getWidth (element) {
return ReactDOM.findDOMNode(element).parentNode.getBoundingClientRect().width
}
function getHeight (element) {
return ReactDOM.findDOMNode(element).parentNode.getBoundingClientRect().height
}
class MyComponent extends Component {
// static propTypes = {
// containerWidth: PropTypes.number.isRequired,
// containerHeight: PropTypes.number.isRequired
// }
render () {
return (
<div style={{
backgroundColor: 'LightBlue',
width: this.props.containerWidth,
height: this.props.containerHeight
}}>
{`${this.props.containerWidth}px x ${this.props.containerHeight}px`}
</div>
)
}
}
MyComponent.propTypes = {
containerWidth: PropTypes.number.isRequired,
containerHeight: PropTypes.number.isRequired
}
const EnhancedComponent = MeasureIt({getWidth: getWidth, getHeight: getHeight})(MyComponent)
const div = document.createElement('div')
document.body.appendChild(div)
ReactDOM.render((
<div style={{
position: 'absolute',
top: 20,
right: 50,
bottom: 20,
left: 50
}}>
<EnhancedComponent />
</div>
), div)