question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why are attribute names "class" and "for" discouraged?

See original GitHub issue

From the docs:

Note: Since JSX is JavaScript, identifiers such as class and for are discouraged as XML attribute names. Instead, React DOM components expect DOM property names like className and htmlFor, 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:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nhunzakercommented, Jul 12, 2017

I’d like to see support for direct use of class and for. There is overlap with #5926, and conversation has picked up again there, so I’ll close this out.

0reactions
sarimartoncommented, Oct 12, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found