Skip to content

Commit 979ee27

Browse files
committed
Merge pull request #862 from cpojer/docs-proptypes
Document PropTypes.renderable and PropTypes.component
2 parents 338ce60 + d73f80e commit 979ee27

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/docs/05-reusable-components.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ React.createClass({
2626
optionalObject: React.PropTypes.object,
2727
optionalString: React.PropTypes.string,
2828

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+
2936
// You can ensure that your prop is limited to specific values by treating
3037
// it as an enum.
3138
optionalEnum: React.PropTypes.oneOf(['News','Photos']),
@@ -91,6 +98,26 @@ React.renderComponent(
9198
);
9299
```
93100

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+
```
94121

95122
## Mixins
96123

0 commit comments

Comments
 (0)