-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
componentDidMount, there is no guarantee that the DOM node is in the document? #9117
Comments
With this code: var div = document.createElement('div');
ReactDOM.render(<MyComponent />, div); The You can use |
@gaearon is there best-practice documentation somewhere for code that runs in |
Ref callback won't help you either. React manages the DOM with respect to the container you pass. So from React's point of view, the moment the DOM is attached to the container, React's job is done. React can't know when that node will be attached to the document. This is something your code is doing, and thus has control over. You could attach it before calling React, and then you'd always be "in the document" by the time Or you could attach it later (as I imagine you're doing). In that case you are the one who knows when it gets attached (because you do the attaching) so the best way is to add your own callback queue that you'll notify when you attach the container. Hope this helps. |
I read the source code and find the comment of
componentDidMount
method.what's the meaning of
there is no guarantee that the DOM node is in the document.
?The text was updated successfully, but these errors were encountered: