Browse Source

Tweak propTypes examples for clarity in oneOfType

main
Ben Alpert 11 years ago
parent
commit
0912eabca4
  1. 11
      docs/05-reusable-components.md

11
docs/05-reusable-components.md

@ -33,6 +33,10 @@ React.createClass({
// A React component.
optionalComponent: React.PropTypes.component,
// You can also declare that a prop is an instance of a class. This uses
// JS's instanceof operator.
optionalMessage: React.PropTypes.instanceOf(Message),
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: React.PropTypes.oneOf(['News', 'Photos']),
@ -40,7 +44,8 @@ React.createClass({
// An object that could be one of many types
optionalUnion: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number
React.PropTypes.number,
React.PropTypes.instanceOf(Message)
]),
// An array of a certain type
@ -52,10 +57,6 @@ React.createClass({
fontSize: React.PropTypes.number
}),
// 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 a warning is
// shown if the prop isn't provided.
requiredFunc: React.PropTypes.func.isRequired,

Loading…
Cancel
Save