Why are attribute names "class" and "for" discouraged?
See original GitHub issueFrom the docs:
Note: Since JSX is JavaScript, identifiers such as
class
andfor
are discouraged as XML attribute names. Instead, React DOM components expect DOM property names likeclassName
andhtmlFor
, respectively.
But the JSX compiler seems to be smart enough to quote keys like "class"
and "for"
(so they’ll work fine even in pre-ES5 environments). So what’s the problem? Why are they discouraged, and what exactly does that mean?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Is the usage of special attributes discouraged? - Stack Overflow
Usually this special attribute are used when working with class objects(magic functions/dunder functions and such) but yes, those attributes ...
Read more >Attribute Names - 2022AB - National Library of Medicine
DC, MeSH Descriptor class - type of MeSH term the concept name represents. ... For "DEPRECATED" or "DISCOURAGED" concepts, the term that should...
Read more >A Complete Guide to Data Attributes | CSS-Tricks
What is discouraged is making up your own attributes, or repurposing existing attributes for unrelated functionality. There are a variety of ...
Read more >HTML attribute reference - HTML: HyperText Markup Language
Attribute Name Elements Description
accept‑charset List of supported charsets.
align, , , , , , , , , , , , , Specifies the horizontal...
Read more >Attribute specifier sequence(since C++11) - cppreference.com
In declarations, attributes may appear both before the whole declaration and directly after the name of the entity that is declared, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d like to see support for direct use of
class
andfor
. There is overlap with #5926, and conversation has picked up again there, so I’ll close this out.In app code I would say it’s outright recommendable to use
class
, especially if you want your codebase to be a lot more ergonomic with tailwind. Suppressing the warning can be done with a console.log override, and typing can be added easily as well. In library code, I would support both.