Files
react.dev/tips/17-children-undefined.md
Jim 7c20ccbc73 Document justification for dangerouslySetInnerHTML, fixes #2256
Conflicts:
	docs/_data/nav_tips.yml
	docs/tips/17-children-undefined.md
2015-01-21 12:47:36 -08:00

803 B

id, title, layout, permalink, prev, next
id title layout permalink prev next
children-undefined this.props.children undefined tips children-undefined.html references-to-components.html use-react-with-other-libraries.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:

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.render(<App></App>, mountNode);

For a more sophisticated example, refer to the last example on the front page.