-
-
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
[Bug]: react/prop-types
not working when prefixing function with underscore _
#3560
Comments
Are you sure components can start with an underscore? Is |
(To be clear, the function name absolutely matters; anything that can't be used in jsx isn't a component) |
Components can start with an underscore. It's true that it goes against standards because components should be in PascalCase. Let me explain my reasoning and see if it makes sense. I am using a state library (mobx) that needs to wrap with HOCs all your components if you want to use it. I wanted to use the same name, so I could export as the wrapped but I also wanted to use the
I fully understand that the component detection makes sense only in PascalCase but why is |
Components shouldn't be arrow functions anyways - do this: function MyComponent(props) { return <div>hi</div>; }
const observed = observer(MyComponent);
export { observed as MyComponent } That said, if |
I don't know if that's what you are asking me to show but check it out https://codesandbox.io/s/relaxed-taussig-fivkl2?file=/src/App.js. Yeah, arrow functions should not be used. I have seen you mention this a lot and I agree fully. |
Since your codesandbox clearly shows that it works, it's thus an oversight/bug in this plugin :-) |
I don't think that generally this is a good idea, because what if I wanted to export my original component function too? For example for using it at a testing file. I will get an error that |
Obviously you can’t export two things under the same name, so my suggestion allows you to trivially rename either or both. That said, exporting things only for testing is a very bad practice - if it’s never used in production without the wrapper, it should never be tested without the wrapper. |
Is there an existing issue for this?
Description Overview
When naming function components with an underscore
_
prefix, thereact/prop-types
rule does not report anything.Other prefixes, like
$
don't seem to create this problem.Expected Behavior
I would expect the rule to appear regardless of the function name.
eslint-plugin-react version
v7.31.10
eslint version
v7.32.0
node version
v10.15.3
The text was updated successfully, but these errors were encountered: