我试图在reactJS中获得div元素,但是我无法实现它。我需要一些专家来查看我的代码,并解决我的问题或新的代码片段将不胜感激。
谢谢
码
this.divElement = React.createRef()
const height = this.divElement.clientHeight
this.setState({ height })
<div
className="col-2-3"
ref={(divElement) => {
this.divElement = divElement
}}
>
</div>发布于 2021-03-19 09:09:46
您应该使用current属性:
this.divElement = React.createRef()
const height = this.divElement.current.clientHeight
this.setState({ height })
<div
className="col-2-3"
ref={this.divElement}
>
</div>https://stackoverflow.com/questions/66705292
复制相似问题