I'm trying to get the exact height of a div in React
<div ref="pageContainer" className="flex flex-start">
<div>
<Title getTitleSize={this.getTitleSize} title={title} size={titleWidth} />
</div>
<div>
{children}
</div>
</div>
By acessing the height of a div with offsetHeight
componentDidMount(){
this.refs.pageContainer.offsetHeight
this.setState({divHeight: this.refs.pageContainer.offsetHeight + 'px'})
}
But I noticed that when directly accessing this.refs.pageContainer.offsetHeight
it returns a different value than when looking up what the actual value is in the object this.refs.pageContainer
For example this.refs.pageContainer.offsetHeight
will return 231
but when looking at the object the value is clearly 251
. It slightly changes the pixel values of other properties on that object as well. Why would the object not return the value it's supposed to have?
Also after the component updates if I access the same value in componentWillUpdate it returns the right value.