Ref gives the wrong element after the first render
See original GitHub issueI have a component called AppPane
which has this render method (simplified):
render({children}) {
return (
<div ref={el => {
console.log(el)
this.rootEl = el
}}>
{children}
</div>
)
}
The first console.log
correctly logs the div
element. But subsequent renders log AppPane
. I can still access this.rootEl.base
to get access to the div, so I do have a workaround.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Ref gives the wrong element after the first render #87 - GitHub
I have a component called AppPane which has this render method (simplified): render({children}) { return ( { console.log(el) this.
Read more >useRef value is undefined on initial render - Stack Overflow
It's because the ref is updated after render time because the DOM element doesn't exist before render time. stackoverflow.com/questions/22238320 ...
Read more >Refs and the DOM - React
When a ref is passed to an element in render , a reference to the node becomes accessible at the current attribute of...
Read more >The Complete Guide to useRef() and Refs in React
How to use React.useRef() hook to create persisted mutable values (also known as references or refs), as well access DOM elements.
Read more >Initializing focus state in React: you might be doing it wrong
But the element is focused, so our initial hasFocus state of false is wrong! To simulate this, I've delayed the hydration of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d never heard of webpackbin… It is awesome.
Here’s the repro. You can click anywhere on the screen to increment the counter. Open up the browser console and you’ll see the issue:
http://www.webpackbin.com/E1WAAp22x
would be useful. Try webpackbin.com if you haven’t yet, it’s awesome. 👍