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

Does consistently rendering new components into the body defeat the purpose of DOM diffing? #3577

Closed
trusktr opened this issue Apr 2, 2015 · 4 comments

Comments

@trusktr
Copy link

trusktr commented Apr 2, 2015

For example, if I do something like

        React.render(
          someComponent,
          $('body')[0]
        );

repeatedly, will that mean that diffing isn't being taken advantage of (the real DOM re-rendered every time), or is there something in place to prevent the real DOM from being re-rendered every time?

@sophiebits
Copy link
Collaborator

No, that'll trigger a diff (so it should be fast) and is the recommended way to rerender a top-level component.

@trusktr
Copy link
Author

trusktr commented Apr 2, 2015

@spicyj Thanks for the super quick reply! Does React keeps track of each element that gets a React component rendered into it? What happens if the target element gets removed?

@sophiebits
Copy link
Collaborator

Yes, it does. You should call React.unmountComponentAtNode before removing the container from the DOM in order to prevent leaks.

@trusktr
Copy link
Author

trusktr commented Apr 30, 2015

@spicyj Aah! Thanks!! This is very valuable.

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