Document PropTypes.renderable and PropTypes.component
cpojer committed
Jan 10, 2014 at 09:31 UTC
d73f80ecb235dbccf7eabbfeac6df001becbbb60
1 file changed
+27
docs/docs/05-reusable-components.md
+27
@@ -26,6 +26,13 @@ React.createClass({
26
optionalObject: React.PropTypes.object,
27
optionalString: React.PropTypes.string,
28
29
+ // Anything that can be rendered: numbers, strings, components or an array
30
+ // containing these types.
31
+ optionalRenderable: React.PropTypes.renderable,
32
+
33
+ // A React component.
34
+ optionalComponent: React.PropTypes.component,
35
+
36
// You can ensure that your prop is limited to specific values by treating
37
// it as an enum.
38
optionalEnum: React.PropTypes.oneOf(['News','Photos']),
@@ -91,6 +98,26 @@ React.renderComponent(
98
);
99
```
100
101
+## Single Child
102
+
103
+With `React.PropTypes.component` you can specify that only a single child can be passed to
104
+a component as children.
105
+
106
+```javascript
107
+var MyComponent = React.createClass({
108
+ propTypes: {
109
+ children: React.PropTypes.component.isRequired
110
+ },
111
+
112
+ render: function() {
113
+ return
114
+ <div>
115
+ {this.props.children} // This must be exactly one element or it will throw.
116
+ </div>;
117
+ }
118
+
119
+});
120
+```
121
122
## Mixins
123