[prop-types] Throw is missing in props validation
when reassign this.props
to props
#1257
Closed
Description
opened on Jun 13, 2017
Hello!
Got an strange behavior when assign this.props
to props
, it will throw an error message is missing in props validation
.
And seems it only happens when use const props = this.props
.
eslint: 4.0.0
eslint-plugin-react: 7.1.0
This piece of code will throw an error.
const Card = React.createClass({
propTypes: {
isReturning: PropTypes.bool,
date: PropTypes.string
},
render() {
const props = this.props;
return (
<div>
{props.isReturning}
{props.departureDate}
</div>
)
}
});
error 'isReturning' is missing in props validation react/prop-types
error 'departureDate' is missing in props validation react/prop-types
This is no error.
const Card = React.createClass({
propTypes: {
isReturning: PropTypes.bool,
date: PropTypes.string
},
render() {
const {isReturning, departureDate} = this.props;
return (
<div>
{isReturning}
{departureDate}
</div>
)
}
});
This is no error.
const Card = React.createClass({
propTypes: {
isReturning: PropTypes.bool,
date: PropTypes.string
},
render() {
return (
<div>
{this.props.isReturning}
{this.props.departureDate}
</div>
)
}
});
Even this is no error.
const Card = React.createClass({
propTypes: {
isReturning: PropTypes.bool,
date: PropTypes.string
},
render() {
const test = this.props;
return (
<div>
{test.isReturning}
{test.departureDate}
</div>
)
}
});
Activity