Skip to content

props.children is UNMOUNTED following update #1602

@yang

Description

@yang

I'm confused by the following behavior. In this example, I have a Wrapper that takes a children prop. When it first renders, clicking mounted? gives us MOUNTED which seems right. But after clicking update to re-render everything, clicking mounted? gives us UNMOUNTED.

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 of Wrapper 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:

/** @jsx React.DOM */
var Wrapper = React.createClass({
  mounted: function() { alert(this.props.children._lifeCycleState); },
  showPopup: function() { alert(this.props.children.getDOMNode()); },
  render: function() {
    return <div>
      {this.props.children}
      <button onClick={this.mounted}>mounted?</button>
      <button onClick={this.props.onUpdate}>update</button>
      <button onClick={this.showPopup}>show popup</button>
    </div>;
  }
});
var App = React.createClass({
  handleUpdate: function() { this.forceUpdate(); },
  render: function() {
    return (
      <Wrapper onUpdate={this.handleUpdate}>
        <div>hello world</div>
      </Wrapper>
    );
  }
});
React.renderComponent(<App />, mountNode);

I believe I'm seeing the same behavior in general when accessing props.children of any ref.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions