no-prop-types
Rule category
Restriction.
What it does
Disallows using propTypes
property in favor of TypeScript or another type-checking solution.
Why is this bad?
PropTypes
were deprecated in April 2017 (v15.5.0).
The propType
checks will be removed from the React package, and using them will be silently ignored. If you’re using propTypes
, it is recommend to migrate to TypeScript or another type-checking solution.
Examples
Failing
import React from 'react';
class ExampleComponent extends React.Component {
static propTypes = {
name: React.PropTypes.string,
};
render() {
return <div>{this.props.name}</div>;
}
}
import React from 'react';
class ExampleComponent extends React.Component {
render() {
return <div>{this.props.name}</div>;
}
}
ExampleComponent.propTypes = {
name: propTypes.string,
};
import React from 'react';
function ExampleComponent(props) {
return <div>{props.name}</div>;
}
ExampleComponent.propTypes = {
name: propTypes.string,
};
Passing
import React from 'react';
interface ExampleComponentProps {
name: string;
}
class ExampleComponent extends React.Component<ExampleComponentProps> {
render() {
return <div>{this.props.name}</div>;
}
}
import React from 'react';
interface ExampleComponentProps {
name: string;
}
function ExampleComponent({ name }: ExampleComponentProps) {
return <div>{name}</div>;
}