That's precisely my issue with React though - JSX is a DSL that looks almost like normal HTML, but differs in small uncanny-valley ways. Sure, it's fine once you're used to it. But it's very much not standard HTML.
That is just wrong on many levels. JSX brings an XML-like notation to JS. It has nothing to do with HTML. react-dom couples your React DOM to the real DOM - thus allowing you to use special JSX elements that create DOM elements. But then you / React interacts with them using the DOM API - not HTML source code.
Things like `htmlFor` or `className` should not be confusing - these are the official DOM properties. `style` in its DOM API also has an object-oriented API and not a string. If you are confused by these things (className vs class, ...) then potentially you started learning JSX from a completely misleading / wrong point.
I know most articles on React / JSX get that wrong, but this non-sense has to stop. After all, you do not write React in the browser because you want to generate HTML - you do write it to manipulate the DOM. On the server, you may want to generate HTML and then this can be misleading (true), but this has not been the main objective.
Telling someone they learned something wrong maybe isn't the best approach when trying to explain why something should not be confusing. Especially when it's a widely held view, maybe the learners are not the problem.
Most people learn JSX when they learn React. It was created by Facebook for React, after all. What does the React docs teach about className?
Here in the intro it doesn't even explain that you need to use className instead of class. It uses it with no explanation. Then it throws in a line about camelCasing and assumes that you understand why it changed.
Finally! In a page that seemingly has nothing to do with JSX we get told to change how we write HTML, but we're not even told why. (The htmlFor section tells us.) No wonder people are confused.
Yes, className is a property of the Element interface but it is not the attribute used when writing HTML. You're still changing how you write HTML. It is no longer standard. That is the point people are making here - JSX introduces enough edge cases that you must learn that it adds equally as much mental overhead as the template DSL for Alpine or Vue. Even if people understand the reasoning and it is not confusing, it's still a shift.
I strongly agree but looking at the Alpine examples it feels like the worst of both worlds to me. At least JSX allows code checking etc, putting code inside HTML attributes has a real ick factor for me.
nickbauman|3 years ago
k4rli|3 years ago
FlorianRappl|3 years ago
Things like `htmlFor` or `className` should not be confusing - these are the official DOM properties. `style` in its DOM API also has an object-oriented API and not a string. If you are confused by these things (className vs class, ...) then potentially you started learning JSX from a completely misleading / wrong point.
I know most articles on React / JSX get that wrong, but this non-sense has to stop. After all, you do not write React in the browser because you want to generate HTML - you do write it to manipulate the DOM. On the server, you may want to generate HTML and then this can be misleading (true), but this has not been the main objective.
cooperadymas|3 years ago
Most people learn JSX when they learn React. It was created by Facebook for React, after all. What does the React docs teach about className?
https://reactjs.org/docs/introducing-jsx.html
Here in the intro it doesn't even explain that you need to use className instead of class. It uses it with no explanation. Then it throws in a line about camelCasing and assumes that you understand why it changed.
Surely the JSX in depth page explains it.
https://reactjs.org/docs/jsx-in-depth.html
It does even less.
https://reactjs.org/docs/dom-elements.html#classname
Finally! In a page that seemingly has nothing to do with JSX we get told to change how we write HTML, but we're not even told why. (The htmlFor section tells us.) No wonder people are confused.
Yes, className is a property of the Element interface but it is not the attribute used when writing HTML. You're still changing how you write HTML. It is no longer standard. That is the point people are making here - JSX introduces enough edge cases that you must learn that it adds equally as much mental overhead as the template DSL for Alpine or Vue. Even if people understand the reasoning and it is not confusing, it's still a shift.
culi|3 years ago
afavour|3 years ago
idoubtit|3 years ago
React does not require JSX, so it's a bit strange to raise the same issue with JSX as with the DSLs of Vue, etc.
If one wants to avoid JSX, it's always possible to write pure JS:
hbrn|3 years ago
But JSX is a standard way to work with React. And Vue templates are a standard way to work with Vue.
j45|3 years ago
savy91|3 years ago
tshaddox|3 years ago
mejutoco|3 years ago
j45|3 years ago
Other times not so much.
frankfrank13|3 years ago
spiderice|3 years ago