Files
react/docs/tips/17-children-undefined.md
T
Cheng Lou dc7242c786 [Docs][Tips] Entry on this.props.children and tweak component ref entry
Component ref entry wasn't registered in nav_tips.
2014-03-31 19:13:16 -07:00

838 B

id, title, layout, permalink, prev
id title layout permalink prev
children-undefined this.props.children undefined tips children-undefined.html references-to-components.html

You can't access the children of your component through this.props.children. this.props.children designates the children being passed onto you by the owner:

/** @jsx React.DOM */

var App = React.createClass({
  componentDidMount: function() {
    // This doesn't refer to the `span`s! It refers to the children between
    // last line's `<App></App>`, which are undefined.
    console.log(this.props.children);
  },

  render: function() {
    return <div><span/><span/></div>;
  }
});

React.renderComponent(<App></App>, mountNode);

To access your own subcomponents (the spans), place refs on them.