Update propTypes documentation.
cpojer committed
Jan 21, 2014 at 16:00 UTC
ca02a068b87a36c727647af443a72ea7c92f46ca
1 file changed
+4
-4
docs/docs/05-reusable-components.md
+4
-4
@@ -12,7 +12,7 @@ When designing interfaces, break down the common design elements (buttons, form
12
13
## Prop Validation
14
15
-As your app grows it's helpful to ensure that your components are used correctly. We do this by allowing you to specify `propTypes`. `React.PropTypes` exports a range of validators that can be used to make sure the data you receive is valid. When an invalid value is provided for a prop, an error will be thrown. Here is an example documenting the different validators provided:
15
+As your app grows it's helpful to ensure that your components are used correctly. We do this by allowing you to specify `propTypes`. `React.PropTypes` exports a range of validators that can be used to make sure the data you receive is valid. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. Note that for performance reasons `propTypes` is only checked in development mode. Here is an example documenting the different validators provided:
16
17
```javascript
18
React.createClass({
@@ -41,14 +41,14 @@ React.createClass({
41
// JS's instanceof operator.
42
someClass: React.PropTypes.instanceOf(SomeClass),
43
44
- // You can chain any of the above with isRequired to make sure an error is
45
- // thrown if the prop isn't provided.
44
+ // You can chain any of the above with isRequired to make sure a warning is
45
+ // shown if the prop isn't provided.
46
requiredFunc: React.PropTypes.func.isRequired
47
48
// You can also specify a custom validator.
49
customProp: function(props, propName, componentName) {
50
if (!/matchme/.test(props[propName])) {
51
- throw new Error('Validation failed!')
51
+ console.warn('Validation failed!');
52
}
53
}
54
},