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

How can I get the original HTMLElement in ReactElements #3898

Closed
huxiaoqi567 opened this issue May 18, 2015 · 3 comments
Closed

How can I get the original HTMLElement in ReactElements #3898

huxiaoqi567 opened this issue May 18, 2015 · 3 comments

Comments

@huxiaoqi567
Copy link

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

@zpao
Copy link
Member

zpao commented May 18, 2015

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"

@zpao zpao closed this as completed May 18, 2015
@huxiaoqi567
Copy link
Author

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;

@sophiebits
Copy link
Collaborator

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);

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

3 participants