4 ms·
I slightly disagree with @machty. I agree that most of the reasons people give for hating on JSX are somewhat off the mark. HOWEVER: the fact that JSX is XML a
by wycats 12y ago
I slightly disagree with @machty. I agree that most of the reasons people give for hating on JSX are somewhat off the mark.
HOWEVER: the fact that JSX is XML and not HTML syntax is a real issue. `<label for="foo">` doesn't work; you have to know that it's `<label htmlFor="foo">`. Same with `class` and `className` and multi-word (`maxwidth` vs. `maxWidth`).
Early on, before React had fully made the decision to stick with raw property names, they understood the value of making JSX "just HTML" (see @petehunt at https://github.com/facebook/react/pull/269#issuecomment-22912842 https://github.com/facebook/react/pull/269#issuecomment-2291..., for example). The decision that they made is totally reasonable, but having to learn an XML dialect of HTML (not XHTML, but a dialect that uses property names for attributes, and disallows normal attribute usage) is not free.
That said, I'm sure it's something you get used to quickly, and isn't something that slows you down much once you understand it.
- lobster_johnson 12y agoIt's not even XML — it's JavaScript. The problems with for/class/etc. problems aren't because of XML, but exist because the preprocessor just translates everything to React.DOM element declarations, and of course "class" et al are reserved words in JS. I agree that's it super awkward. I have no idea why they don't let the preprocessor be HTML-aware and translates class into className directly. I can't see how something like "class" would clash with the surrounding JS syntax given that it's specific to the local tag syntax. <Foo> isn't valid JS, after all, so why should "class" not be valid JSX? It creates a maintenance problem, too, because React has to play catch up with every HTML tag and attribute and every CSS property.