no-unused-state
+ arrow function property + destructuring #1363
Closed
Description
opened on Aug 12, 2017
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
Activity