You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.1 KiB
1.1 KiB
id | title | layout | permalink | prev | next |
---|---|---|---|---|---|
children-prop-type | Type of the children prop | cookbook | children-prop-type.html | style-prop-value-px.html | controlled-input-null-value.html |
Usually, a component's this.props.children
is an array of components:
/** @jsx React.DOM */
var GenericWrapper = React.createClass({
componentDidMount: function() {
console.log(Array.isArray(this.props.children)); // => true
},
render: function() {
return <div />;
}
});
React.renderComponent(
<GenericWrapper><span/><span/><span/></GenericWrapper>,
mountNode
);
To save an extra array allocation, it returns the component itself without the array wrapper when there's only one child.
/** @jsx React.DOM */
var GenericWrapper = React.createClass({
componentDidMount: function() {
// **warning**: yields 5 for length of the string 'hello', not 1 for the
// length of the non-existant array wrapper!
console.log(this.props.children.length);
},
render: function() {
return <div />;
}
});
React.renderComponent(<GenericWrapper>hello</GenericWrapper>, mountNode);