@samitouri / QOS-React-2 / commits / 30646c9c1e

Add docs for new prop types

Ben Alpert committed Feb 13, 2014 at 22:59 UTC 30646c9c1e207f813d97465068f03ea401353b20
1 file changed +17 -2
docs/docs/05-reusable-components.md
+17 -2
@@ -35,11 +35,23 @@ React.createClass({
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']),
38 + optionalEnum: React.PropTypes.oneOf(['News', 'Photos']),
39
40 - // Expect an array of a certain propType
40 + // An object that could be one of many types
41 + optionalUnion: React.PropTypes.oneOfType([
42 + React.PropTypes.string,
43 + React.PropTypes.number
44 + ])
45 +
46 + // An array of a certain type
47 optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.number)
48
49 + // An object taking on a particular shape
50 + optionalObjectWithShape: React.PropTypes.shape({
51 + color: React.PropTypes.string,
52 + fontSize: React.PropTypes.number
53 + }),
54 +
55 // You can also declare that a prop is an instance of a class. This uses
56 // JS's instanceof operator.
57 someClass: React.PropTypes.instanceOf(SomeClass),
@@ -48,6 +60,9 @@ React.createClass({
60 // shown if the prop isn't provided.
61 requiredFunc: React.PropTypes.func.isRequired
62
63 + // An object of any kind
64 + requiredAny: React.PropTypes.any.isRequired
65 +
66 // You can also specify a custom validator.
67 customProp: function(props, propName, componentName) {
68 if (!/matchme/.test(props[propName])) {