Is there an existing issue for this?
Description Overview
The react/no-this-in-sfc rule reports an error if a function component has some internal function that uses this that refers to an entity other than the function component.
const MyComponent = () => {
function doMagik(this: any, arg: any) {
this.value = arg; // error here
}
class Internal {
private value: number;
constructor() {
this.value = 10; // and here
}
}
doMagik(new Internal());
return <div />;
};
IMHO whether writing code this way is a "good practice" is a separate concern that could be addressed by a separate linting rule or a config option under this one. The point is that the rule as it stands today reports a false positive. If I understand its intent correctly, that is.
Thank you!
Expected Behavior
The rule should either:
- not report any errors in the above scenarios;
- have a flag that would allow the developer to adjust its behavior so that it does not report any errors in the above scenarios.
eslint-plugin-react version
^7.37.5
eslint version
v9.39.4
node version
v24.14.0
Is there an existing issue for this?
Description Overview
The
react/no-this-in-sfcrule reports an error if a function component has some internal function that usesthisthat refers to an entity other than the function component.IMHO whether writing code this way is a "good practice" is a separate concern that could be addressed by a separate linting rule or a config option under this one. The point is that the rule as it stands today reports a false positive. If I understand its intent correctly, that is.
Thank you!
Expected Behavior
The rule should either:
eslint-plugin-react version
^7.37.5
eslint version
v9.39.4
node version
v24.14.0