zarzavat 5 days ago

I'm annoyed to learn that even the original PHP version had `class=` working.

1
MrJohz 5 days ago

In fairness, `className` makes a lot of sense given that the native DOM uses the `className` attribute rather than `class`. In that sense, it's a consistent choice, just a consistent choice with the DOM rather than with HTML.

The bigger issue is the changes to events and how they get fired, some of which make sense, others of which just break people's expectations of how Javascript should work when they move to non-React projects.

littlecranky67 5 days ago

Preact fixed that years ago and you can just use class=

MrJohz 4 days ago

It's not about "fixing" it, it's about choosing what you want to be consistent with. You can either be consistent with the DOM API (e.g. `document.getElementById().className = "hello"`) or with HTML (i.e. `class=...`). Both are valid choices — I personally prefer className because this is Javascript, so consistency with the DOM makes more sense, but JSX is designed to be an HTML-like syntax so I can see both ways.

The bigger difference that React makes from other frameworks, and from the DOM, is when it comes to events, in particular with events like `onChange` actually behaving more like the `onInput` event.

littlecranky67 3 days ago

To be fair, choice would be to allow both in your JSX like Preact does. Usually I wouldn't bother as I get your point with consitency. But from a practical standpoint, whenever you paste some HTML code from somewhere else, the first thing I need to do is search/replace class= to className=. Probably more relevant for tailwind/bootstrap users than MUI.

MrJohz 2 days ago

That's true, but there are various other syntax differences that mean that pasting HTML is always going to require some fixing up. For example, JSX requires all elements to have closing tags or use the /> syntax, whereas HTML has elements like input or img where's that's not correct.

That said, "class" shows up a lot more in most html than "input", so I can see the advantage of being consistent with html there.

nsonha 4 days ago

the only reason I can think of is for the dot notation assignment (not clashing with the class keyword). No one cares about consistency with DOM API in this context. Given the syntax, they most definitely expect consistency with HTML