I'm trying to use React.createRef()
to access the dimensions of a DOM element in React.
I create in in the constructor like
constructor(props) {
super(props);
this.container = React.createRef()
}
And assigning it like
<div id="container"
ref={this.container}
>...children</div>
However when I log this out from within componentDidMount()
componentDidMount(){
console.log(this.container);
}
I see {current: null}
in the console. But if I expand this object I can see everything I want access to like clientHeight which has a value.
How do I access these attributes? At the moment this.container.current.clientHeight
returns null.
Thanks