Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 828 Bytes

17-children-undefined.md

File metadata and controls

28 lines (23 loc) · 828 Bytes
id title layout permalink prev next
children-undefined
this.props.children undefined
tips
children-undefined.html
expose-component-functions.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>;
  }
});

ReactDOM.render(<App></App>, mountNode);

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