react/no-typos
Disallow misspelled lifecycle methods, static properties, and prop types
React finds componentDidMount, propTypes, and defaultProps by name. If you write componentDidmount or PropTypes, nothing fails. React never calls the method and never checks the props.
The rule reports four kinds of mistakes in a component:
- A lifecycle method, such as
componentDidMountorshouldComponentUpdate, with the wrong capitalization. getDerivedStateFromPropswithoutstatic.propTypes,contextTypes,childContextTypes, ordefaultPropswith the wrong capitalization.- A type that the
prop-typespackage doesn't have, such asPropTypes.boolean, or anything other than.isRequiredafter a type. This only works if the file importsprop-typesorreact.
It also reports import "react" and import "prop-types", which don't import any names.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"react/no-typos" = "error" # or "warn"Examples#
example.jsx3 problems
class Clock extends React.Component {
static DefaultPropsTypo in static class property declaration = { interval: 1000 };
getDerivedStateFromProps(props) {Lifecycle method should be static: getDerivedStateFromProps
return { interval: props.interval };
}
componentDidmount() {Typo in component lifecycle method declaration: componentDidmount should be componentDidMount
this.start();
}
}example.jsx2 problems
import PropTypes from "prop-types";
class Clock extends React.Component {
static propTypes = {
running: PropTypes.booleanTypo in declared prop type: boolean,
interval: PropTypes.number.isrequiredTypo in prop type chain qualifier: isrequired,
};
}example.jsxNo problems
import PropTypes from "prop-types";
class Clock extends React.Component {
static propTypes = {
running: PropTypes.bool,
interval: PropTypes.number.isRequired,
};
static defaultProps = { interval: 1000 };
static getDerivedStateFromProps(props) {
return { interval: props.interval };
}
componentDidMount() {
this.start();
}
}