Eslint-plugin-react: Linting the React props: props.hasOwnProperty.call('x') -> Error: react/prop-types

Created on 13 Sep 2016  路  3Comments  路  Source: yannickcr/eslint-plugin-react

I have this issue with ESLint and React props / propTypes

...
this.props.hasOwnProperty('modelConfig');   /* =>  ESLint error: "no-prototype-builtins"   */
this.props.hasOwnProperty.call(this.props, 'modelConfig');   /*  => ESLint error: "react/prop-types"  (underlined is the "call" word) */
...
MyClass.propTypes = {
  modelConfig: ImmutablePropTypes.map,
};

How to solve it?

eslint question

Most helpful comment

const { hasOwnProperty } = this.props; and then call it that way.

You don't want to call functions directly off of this.props anyways, since that will set this.props as the this value in the function.

All 3 comments

const { hasOwnProperty } = this.props; and then call it that way.

You don't want to call functions directly off of this.props anyways, since that will set this.props as the this value in the function.

Alternatively, if that's not a prop, Object.prototype.hasOwnProperty.call(this.props, 'modelConfig');

@ljharb Thank you! I love this, it is so easy with ES6 :-)

Was this page helpful?
0 / 5 - 0 ratings