You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
React.createClass({
propTypes: {
// You can declare that a prop is a specific JS primitive. By default, these
// are all optional.
optionalArray: React.PropTypes.array,
optionalBool: React.PropTypes.bool,
optionalFunc: React.PropTypes.func,
optionalNumber: React.PropTypes.number,
optionalObject: React.PropTypes.object,
optionalString: React.PropTypes.string,
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: React.PropTypes.oneOf(['News','Photos']),
// You can also declare that a prop is an instance of a class. This uses
// JS's instanceof operator.
someClass: React.PropTypes.instanceOf(SomeClass),
// You can chain any of the above with isRequired to make sure an error is
// thrown if the prop isn't provided.
requiredFunc: React.PropTypes.func.isRequired
// You can also specify a custom validator.
customProp: function(props, propName, componentName) {
if (!/matchme/.test(props[propName])) {
throw new Error('Validation failed!')
}
}
},
/* ... */
});
Using props validation ensure that each component is used correctly, through a defined interface.
It's like assertions for a component done in a declarative way.
This should be used almost everywhere to help detect the consistency issues that could happen when the application grows.
We need to fail-fast to detect problems
The text was updated successfully, but these errors were encountered:
http://facebook.github.io/react/docs/reusable-components.html
Using props validation ensure that each component is used correctly, through a defined interface.
It's like assertions for a component done in a declarative way.
This should be used almost everywhere to help detect the consistency issues that could happen when the application grows.
We need to fail-fast to detect problems
The text was updated successfully, but these errors were encountered: