Skip to content

Commit

Permalink
Add examples of correctly specified propTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDog authored and Andreas Sommer committed Sep 9, 2016
1 parent fd06c06 commit 36a4a40
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/rules/prop-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ function Hello({ name }) {
}
```

Examples of correct usage without warnings:

```jsx
var Hello = React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired,
},
render: function() {
return <div>Hello {this.props.name}</div>;
},
});

// Or in ES6:
class HelloEs6 extends React.Component {
render() {
return <div>Hello {this.props.name}</div>;
}
}
HelloEs6.propTypes = {
name: React.PropTypes.string.isRequired,
};

// ES6 + Public Class Fields (draft: https://tc39.github.io/proposal-class-public-fields/)
class HelloEs6WithPublicClassField extends React.Component {
static propTypes = {
name: React.PropTypes.string.isRequired,
}
render() {
return <div>Hello {this.props.name}</div>;
}
}
```

The following patterns are not considered warnings:

```jsx
Expand Down

0 comments on commit 36a4a40

Please sign in to comment.