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
[0.14] this.refs... not returning element from specific components.. #5074
Comments
Are you confused because it doesn't return a DOM node? Only built-in DOM components give the DOM node; composite components are unaffected. |
Yes I am, I was just looking into the documentation and noticed that we should be using |
@spicyj @m4tthumphrey can you help me with this i facing same problem |
@TonyFrancis Wherever you are using Method 1: If the ref points to a standard component (DOM node, such as Method 2: If the ref points to a composite component (a custom component you have created yourself) you need to use the new So if you have something like the following in your code function componentDidMount: function() {
var el1 = this.refs.ref1.getDOMNode();
var el2 = this.refs.ref2.getDOMNode();
// ...
},
function render() {
return (
<div>
<input ref="ref1" />
<MyComponent ref="ref2" />
</div>
);
} you need to change it like so: function componentDidMount: function() {
var el1 = this.refs.ref1;
var el2 = ReactDOM.findDOMNode(this.refs.ref2);
// ...
},
function render() {
return (
<div>
<input ref="ref1" />
<MyComponent ref="ref2" />
</div>
);
} Hope that clears it up. If you haven't updated your code before 0.15, it will error. |
@m4tthumphrey solved my problem child reference not formed at begining so needed a time delay so refs to be available |
I'm not sure what the cause or pattern is yet but some of my components are causing
this.refs.name
to return the following object from withincomponentDidMount()
. Other components are fine however.Edit: See the bottom of this post for a possible cause.
I can post the whole object if necessary...
A snippet from my component:
As I'm typing this I've noticed that this is using a custom component
TextField
when setting the ref, maybe this is the problem and could be a bug; assigning a ref to a custom component type? Note thatthis.refs.name.getDOMNode()
works correctly albeit with the 0.14 warning.The text was updated successfully, but these errors were encountered: