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?
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 :-)
Most helpful comment
const { hasOwnProperty } = this.props;and then call it that way.You don't want to call functions directly off of
this.propsanyways, since that will setthis.propsas thethisvalue in the function.