-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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-access-state-in-setstate] inspects non-react classes #2464
Comments
Can you provide some specific code that's detected as a React component? |
@ljharb for example: class Foo extends Abstract {
update = () => {
const result = this.getResult ( this.state.foo );
return this.setState ({ result });
};
} |
Certainly that shouldn't be detected as a React component, thanks. |
I mean it depends, how do you know Abstract isn't something that extends |
Sure, but a) it is in incredibly discouraged and bad pattern to use inheritance hierarchies in React, so you shouldn't be doing that anyways; and b) there's a jsdoc "extends" comment you're already required to use in those situations to opt your component into being detected by this plugin. |
The
react/no-access-state-in-setstate
rule can find errors in non-react classes, which doesn't make a lot of sense.In my specific use case I'm using overstated for state management, which provides a similar API to React's own API for updating the state, which trips this rule.
It's impossible in general to statically detect if a class is a react component or not, e.g.
class Foo extends Abstract {}
, who knows if that's a react component or not.Therefor I propose adding an option for blacklisting specific classes, so that I can tell the rule that "Abstract" in my example above is not a react class.
The text was updated successfully, but these errors were encountered: