Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref gives the wrong element after the first render #87

Closed
chrisdavies opened this issue Mar 12, 2016 · 6 comments
Closed

Ref gives the wrong element after the first render #87

chrisdavies opened this issue Mar 12, 2016 · 6 comments

Comments

@chrisdavies
Copy link

I 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.

@developit
Copy link
Member

Hi Chris - to clarify: is the subsequent re-rendering triggered by setState()/forceUpdate()?

@chrisdavies
Copy link
Author

Hey. Sorry. It's by setState in a parent component. Basically, I have state in a parent that is determining which AppPane is current.

@chrisdavies
Copy link
Author

I can try to put together a small example.

@developit
Copy link
Member

would be useful. Try webpackbin.com if you haven't yet, it's awesome. 👍

@chrisdavies
Copy link
Author

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

developit added a commit that referenced this issue Mar 12, 2016
developit added a commit that referenced this issue Mar 12, 2016
@developit
Copy link
Member

Fix for this is released in 4.3.0.
Confirmed, fixes your repro: http://www.webpackbin.com/VJXWiDp2e

marvinhagemeister added a commit that referenced this issue Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants