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
react/no-unused-prop-types
false positives when passing props as an argument
#2155
Comments
This isn't really something we can statically analyze - in general, you shouldn't be passing around the entire props (or state) object. If you destructure |
I thought about detecting method calls with |
In your specific simple case, it could certainly be done - but, anyone from outside the file could call I don't think it's worth the complexity to try to target only some of the patterns, when the entire thing can be avoided by not having the antipattern of passing the props object around. |
Sometimes passing all props makes it easier to follow. Especially when you need more than one prop and need to call it in different lifecycle methods. |
I'm sure it's subjective, but I would argue that in that case, you'd want to do this:
You can still pass an object, but it's not the actual props object, it's an explicit object you created. |
I agree your solution is better for this scenario, but if you need it in more than one place (in constructor & CWRP), or use many props inside |
I see that as a feature, not a bug, since if you do forget, your tests will fail :-) |
This seems answered - don't pass the props or state objects anywhere. |
In this scenario
something
is marked as unused although it is used.It's similar to #855, but here the code is part of the class.
The text was updated successfully, but these errors were encountered: