Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unused-state + arrow function property + destructuring #1363

Closed
daltones opened this issue Aug 12, 2017 · 1 comment
Closed

no-unused-state + arrow function property + destructuring #1363

daltones opened this issue Aug 12, 2017 · 1 comment

Comments

@daltones
Copy link
Contributor

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

@ljharb
Copy link
Member

ljharb commented Oct 18, 2017

Fixed with #1411

@ljharb ljharb closed this as completed Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants