I’m tying to position a circle in the middle of the component’s root DOM element:
var App = React.createClass({
render: function() {
return <svg ref="svg">
<circle r="9" cx={this.centerX()} cy="15"/>
</svg>;
},
centerX: function() {
var svg = this.refs.svg.getDOMNode();
return svg.offsetLeft + Math.round(svg.offsetWidth / 2);
}
});
Chicken-and-egg problem takes place here: this.refs
is undefined on the first render. What’s the best way to solve this it? I would prefer not to reference external DOM nodes (such as document.body
).