简体   繁体   中英

How can you find the ReactDOM root from inside the render tree?

findDOMNode can be used to find the DOM node of a given Component, but I'm not sure how to traverse the tree to find the same node that was passed initially to ReactDOM.render() .

eg

Discover the element root from inside App, where we have:

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

Does React store this internally?

Why exactly are you trying to find the element with the "root" id? The second argument of the render function is getting that element just so you know.

But the real question is do you want the React component or the actual DOM element it's been bound too, since everything after this is the VDOM (Virual DOM).

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