-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
I found a case where no-unused-state raises a false-positive:
import React from 'react';
import PropTypes from 'prop-types';
export default class MyComponent extends React.PureComponent {
static propTypes = {
prop1: PropTypes.string,
};
state = {
state1: false,
};
handleClick = () => {
const {
props: {prop1},
state: {state1},
} = this;
console.log(prop1);
console.log(state1);
};
render() {
return <button onClick={this.handleClick} />;
}
}Warns: Unused state field: 'state1' (react/no-unused-state)
It seems to be specific of arrow functions as properties and that “two-level” destructuring.
It won't warn with the following:
- straight access like
this.state.state1 - simple destructuring like
const {state1} = this.state; - unbounded method like
handleClick() {}
eslint-plugin-react: v7.2.0
eslint: v4.4.1