40 lines
742 B
Plaintext
40 lines
742 B
Plaintext
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
|
|
|
|
----
|
|
class Rating extends React.Component {
|
|
render() {
|
|
return ( <div>{this.props.rating}</div> );
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
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)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|