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 Classes starting with a Lowercase don't call any methods inside the class. #4695
Comments
I believe JSX has a convention in which lowercase tags are considered to be primitives, and so it's transformed into With uppercase JSX tags, it's transformed into |
@kmeht Yes, you're correct. It has always been a convention that classnames start with an uppercase, and it's one that JSX enforces. Otherwise, there would be namespace collisions and no way for us to determine if the user intended to insert a component or a DOM node. It's documented here: https://facebook.github.io/react/docs/jsx-in-depth.html#html-tags-vs.-react-components And the design justification is discussed here: https://gist.github.com/sebmarkbage/f1f4ba40816e7d7848ad |
Thanks, I checked the docs here, so missed the more detailed info you provided: |
@giantelk Want to send a PR to make the docs clearer? |
We did warn in a previous version but we only kept it for one version. We no longer support our transform tools so we won't be adding any more warnings about this. |
That sucks. No error, no warning. Whoever is supporting the transform tools On Tue, Aug 25, 2015 at 12:53 AM, Paul O’Shannessy <notifications@github.com
Cheers, |
We can probably warn if you have a lowercase displayName… |
@spicyj Warn on lowercase displayName sounds like it would throw a false positive if displayName is being set automatically from the filename and the filename is something like "./UserDashboard/index.jsx" and being included with |
@jimbolla That's true. We recommend doing
though. |
Eh. I don't like that. It's just adding redundancy and an extra line of code to every file. The ideal situation would be to have the ability to customize how displayName gets generated because the value that would actually be useful for display name is the full relative path of the source file, equivalent to something like |
I’m closing this as it doesn’t appear like we’d have a good way of warning for functional components or classes anyway, and supporting this only for We can’t warn on the declaration site because the components are defined by the user, and we can’t warn in This can probably be implemented as a lint rule in https://github.com/yannickcr/eslint-plugin-react so please feel free to suggest this idea there. |
If a React Class name starts with a lowercase letter then no methods inside the class get called, i.e. nothing Renders, and you don't get any error message in the Browser console. You will see the element in the DOM, but just empty contents, in this case
myHeader
. If you rename the Class toMyHeader
, and change it here too, then it works:React.render(<MyHeader />, document.body)
.See the simple example below, you get nothing in the browser console or web page, until change
myHeader
toMyHeader
.btw - this drove me nuts for about 30mins until I ran out of things to try and thought, there's no way it could be a lower VS upper-case issue.
The text was updated successfully, but these errors were encountered: