Move variables out of state.

This commit is contained in:
Richard Lewis 2018-03-26 11:53:39 +01:00
parent 700515cce3
commit e3a3dec8a2
1 changed files with 4 additions and 8 deletions

View File

@ -43,11 +43,7 @@ module.exports = React.createClass({
document.body.appendChild(this.tooltipContainer); document.body.appendChild(this.tooltipContainer);
window.addEventListener('scroll', this._renderTooltip, true); window.addEventListener('scroll', this._renderTooltip, true);
const parent = ReactDOM.findDOMNode(this).parentNode; this.parent = ReactDOM.findDOMNode(this).parentNode;
this.state={
parent,
parentBox: parent.getBoundingClientRect(),
};
this._renderTooltip(); this._renderTooltip();
}, },
@ -70,7 +66,7 @@ module.exports = React.createClass({
}, },
_updatePosition(style) { _updatePosition(style) {
const parentBox = this.state.parent.getBoundingClientRect(); const parentBox = this.parent.getBoundingClientRect();
let offset = 0; let offset = 0;
if (parentBox.height > MIN_TOOLTIP_HEIGHT) { if (parentBox.height > MIN_TOOLTIP_HEIGHT) {
offset = Math.floor((parentBox.height - MIN_TOOLTIP_HEIGHT) / 2); offset = Math.floor((parentBox.height - MIN_TOOLTIP_HEIGHT) / 2);
@ -117,8 +113,8 @@ module.exports = React.createClass({
render: function() { render: function() {
// Render a placeholder // Render a placeholder
return ( return (
<div className={ this.props.className } > <div className={this.props.className} >
</div> </div>
); );
} },
}); });