4 ms·
"What should go into JSX 2.0?" would be a much clearer title outside of the context of the GitHub issue.
by JBiserkov 10y ago
"What should go into JSX 2.0?" would be a much clearer title outside of the context of the GitHub issue.
- blablabla123 10y agoYup, even the issues not marked controversial seem so to me. I think JSX is quite nice but it has its limits/annoyances. One is obviously that it's not real HTML5. I would like to see a successor that is more like HTML5 without the X. No idea how that could be realized though... ;)
- rattray 10y agoSorry, what do you mean by this? (For those unfamiliar with the deviations)
- djur 10y agoI started using React/JSX professionally in the last few months, so some of these are fresh in my head. Differences I'm aware of: 1) JSX creates virtual DOM objects, not HTML tags. In places where the DOM and HTML use different names for the same thing, JSX uses the DOM's name. In particular, the "class" attribute is called "className" and the "style" attribute takes an object like { color: "white" } instead of a string like "color: white" (and the keys are like "backgroundImage" rather than "background-image"). The latter rarely comes up, but the former bites me all the time when incorporating markup from designers. 2) JSX requires all tags to be closed, like XHTML and all XML dialects. HTML 5 declares some tags to be self-closing, like IMG. 3) JSX removes whitespace padding inside elements. This usually results in the same visual result, except for those cases where HTML actually cares about extra whitespace (like in PRE and TEXTAREA). 4) Regarding TEXTAREA, you're encouraged not to use the inner content of the tag to define its default value. Instead, you treat it like an INPUT. (I think this is if anything an improvement.) 5) INPUT tags have some special behavior related to default values, but that's really more about React than JSX per se. Overall I have found JSX pretty easy to get into. I appreciate that it really is just a very thin layer over underlying JS. I'm not totally sold on this approach versus the many, many, many other HTML templating systems out there, but at least it's easy to understand.
- rattray 10y agoAh, I see, thanks for sharing. Yes, I personally view most of those deviations as positive.
- blablabla123 10y agoRegarding 1)... like 5) that's React, so you could write a JSX transpiler that creates actual DOM objects.
- deleted 10y ago[deleted]
- lmm 10y agoThe best approach I've ever seen is Wicket, where you write pure HTML with just ID attributes, and all the logic / control flow is in the code. But the code for a component corresponds directly to the HTML (by having the same filenames), and each component can be very small and self-contained / compositional. It ends up being the best example of the good side of OO I've seen.
- sctb 10y agoThank you, we've updated the title.