From 36a4a406d5be556ae8f43c63daab96ec51cf9df3 Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Fri, 9 Sep 2016 07:50:03 +0200 Subject: [PATCH] Add examples of correctly specified propTypes --- docs/rules/prop-types.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/rules/prop-types.md b/docs/rules/prop-types.md index 2432ed30c4..c705a30d2a 100644 --- a/docs/rules/prop-types.md +++ b/docs/rules/prop-types.md @@ -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
Hello {this.props.name}
; + }, +}); + +// Or in ES6: +class HelloEs6 extends React.Component { + render() { + return
Hello {this.props.name}
; + } +} +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
Hello {this.props.name}
; + } +} +``` + The following patterns are not considered warnings: ```jsx