
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
46 lines
963 B
Plaintext
46 lines
963 B
Plaintext
== Why is this an issue?
|
|
|
|
If the type of a ``++props++`` property is not defined there is a great chance one will wrongly use the value returned by the property and generate a not expected behavior of the application.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
class Rating extends React.Component {
|
|
render() {
|
|
return ( <div>{this.props.rating}</div> );
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
import PropTypes from 'prop-types';
|
|
|
|
class Rating extends React.Component {
|
|
render() {
|
|
return ( <div>{this.props.rating}</div> );
|
|
}
|
|
}
|
|
|
|
Rating.propTypes = {
|
|
rating: PropTypes.number.isRequired
|
|
};
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 23 Feb 2018, 11:57:13 Alexandre Gigleux wrote:
|
|
Covered by ESLint for Reach: \https://github.com/yannickcr/eslint-plugin-react/blob/HEAD/docs/rules/prop-types.md (react/prop-types)
|
|
|
|
endif::env-github,rspecator-view[]
|