I am trying to access the width and height styles of a div in React but I have been running into one problem. This is what I got so far:
componentDidMount()
You should use ReactDOM.findDOMNode
method and work from there. Here's the code that does what you need.
var Hello = React.createClass({
componentDidMount: function() {
var elem = ReactDOM.findDOMNode(this.refs.container);
console.log(elem.offsetWidth, elem.offsetHeight);
},
render: function() {
return (
Hello world
);
}
});
ReactDOM.render(
,
document.getElementById('container')
);
jsFiddle