简体   繁体   中英

Cannot access DOM object through createRef

I'm very new to React JS. I'm trying to access the dom object of an iframe for changing its size.

I have the iframe in my render - <iframe ref={this.myRef} ></iframe>

And in the constructor, I have

this.myRef = React.createRef()

When I console log(this.myRef.current), I get back null eventhough when I console (this.myRef), it is shown to have current inside it and it holds many objects.

我使用的是“ react-dom”版本16.0.0,我已升级到最新版本-16.7.0,并且开始工作!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM