-
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
props.children
is UNMOUNTED
following update
#1602
Comments
As the underscore in front of its name suggests, There's no current way to get a reference to the mounted children instance, but you can use a ref if you wrap them in another div: var Wrapper = React.createClass({
showPopup: function() { alert(this.refs.childWrapper.getDOMNode()); },
render: function() {
return <div>
<div ref="childWrapper">
{this.props.children}
</div>
<button onClick={this.props.onUpdate}>update</button>
<button onClick={this.showPopup}>show popup</button>
</div>;
}
}); Hope that helps. |
I'm not actually using Inserting an intermediate |
Sorry, there's no way right now to get a ref to children that are passed in. After #1373 it may be possible to do so using cloneWithProps. |
Thanks, I had been following that. Actually, following up on your mentioning
Perhaps there are pitfalls to using Also, some random other experimentation suggests that at least one other way to actually get the DOM node using a pass-through component without the extra PassThrough = React.createClass
render: -> @props.children
Wrapper = React.createClass
render: ->
R.div {},
PassThrough {ref: 'handle'}, @props.children
R.button {onClick: => console.log @refs.handle.getDOMNode()}, 'inspect DOM' |
Ah yes, you're right on both counts. |
I'm confused by the following behavior. In this example, I have a
Wrapper
that takes achildren
prop. When it first renders, clickingmounted?
gives usMOUNTED
which seems right. But after clickingupdate
to re-render everything, clickingmounted?
gives usUNMOUNTED
.For some real-use-case context, this gave me errors when accessing
this.props.children.getDOMNode()
to pass to a third-party library for displaying a pop-up menu around the given node. The given child was not responsible for knowing about the popup logic; instead, it's the sole purpose ofWrapper
to show a contextual menu at the location of the given component.Pasting this into a Live JSX Editor on http://facebook.github.io/react/ should work:
I believe I'm seeing the same behavior in general when accessing
props.children
of any ref.The text was updated successfully, but these errors were encountered: