I am trying to get div element in reactJS but I am not able to achieve it. I need some expert to look into my code and resolve my issue or new code snippet would be appreciated.
Thanks
Code
this.divElement = React.createRef()
const height = this.divElement.clientHeight
this.setState({ height })
<div
className="col-2-3"
ref={(divElement) => {
this.divElement = divElement
}}
>
</div>
You should use the current
property:
this.divElement = React.createRef()
const height = this.divElement.current.clientHeight
this.setState({ height })
<div
className="col-2-3"
ref={this.divElement}
>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.