The children passed to a component, either via JSX nesting or via the third+ argument to React.createElement
, shows up in the component as this.props.children
:
var MyLabel = React.createClass({
render: function() {
return React.createElement("label", {className: "label"},
React.createElement("span", {className: "label"}, this.props.label),
this.props.children
);
}
});
var App = React.createClass({
render: function() {
return React.createElement(MyLabel, {label: "Here is the label prop"},
React.createElement("div", {},
React.createElement("input", {type: "text", value: "And here is a child"})
)
);
}
});
Example: http://jsfiddle.net/BinaryMuse/typ1f2mf/; docs: http://facebook.github.io/react/docs/multiple-components.html#children
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…