React: How can I get the original HTMLElement in ReactElements

Created on 18 May 2015  ·  3Comments  ·  Source: facebook/react

hi, I just don't know how to get a original HTMLElement in ReactElement? Just like getDOMNode() in ReactComponent?

Most helpful comment

A ReactElement doesn't correspond to a DOM node until you mount it in the DOM using React.render.

var element = <ScrollView><Text>hello</Text></ScrollView>;
var component = React.render(element, container);
var node = React.findDOMNode(component);

All 3 comments

Elements are light-weight objects with no knowledge of HTML elements. I'm not sure exactly what you're asking or why you would need it but if you're looking to get "div" from

you can access .type.

var el = <div />;
console.log(el.type); // "div"

like this <ScrollView><Text>hello</Text></ScrollView> , "ScrollView.children" return [ReactElement],
but i can't get the real HTMLElementNode by ReactElement. Because I want getComputedStyle of the <Text> node;

A ReactElement doesn't correspond to a DOM node until you mount it in the DOM using React.render.

var element = <ScrollView><Text>hello</Text></ScrollView>;
var component = React.render(element, container);
var node = React.findDOMNode(component);
Was this page helpful?
0 / 5 - 0 ratings