Eslint-plugin-react: `react/no-unused-prop-types` with reassigning this

Created on 14 Aug 2018  路  3Comments  路  Source: yannickcr/eslint-plugin-react

Sorry if this is a duplicate, but I couldn't find it.

I get the ubiquitous PropType is defined but prop is never used when using the following (stripped down) code. I assume this is all because I am re-assigning this to self as if I replace self.props with this.props, everything works.

import React, { Component } from 'react';
import PropTypes from 'prop-types';

import loggerShape from '../propTypes/logger';

class Video extends Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const self = this;

    const { src, logger, contentType } = self.props;

   ...

    function addListener(eventName, logMethod = 'info') {
      self.player.on(eventName, () => {
        logger[logMethod](`player event - ${eventName} - ${src}`);
      });
    }

    addListener('abort', 'error');

    setSource({
      src,
      type: contentType,
    });

   ...
  }

  render() {
    return (
      <div className="video">
         ...
      </div>
    );
  }
}

Video.propTypes = {
  contentType: PropTypes.string.isRequired,
  logger: loggerShape.isRequired,
  src: PropTypes.string.isRequired,
};

export default Video;

ESLint versions

"eslint": "4.19.1",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jest": "21.21.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "7.11.0",
enhancement help wanted

Most helpful comment

Understood :-) i just mean that var self = this shouldn't really ever appear in any code authored in an ES2015+ environment.

All 3 comments

Since arrow functions exist, I鈥檓 not sure why you鈥檇 need the obsolete this var pattern ever again - but it seems like something we should be able to support.

@ljharb, just to be clear, all 3 props fail, not just the one I put inside addListener.

Understood :-) i just mean that var self = this shouldn't really ever appear in any code authored in an ES2015+ environment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inian picture inian  路  3Comments

mydearxym picture mydearxym  路  3Comments

otakustay picture otakustay  路  3Comments

mericsson picture mericsson  路  3Comments

isnifer picture isnifer  路  3Comments