I admit that the parens and braces mess causes significant readability issues (though less than the tag soup). E.g. coffeescript gets rid of this problem very elegantly.
But, when coffeescript is discussed, it's "syntax doesn't matter, just use ES6" but when it's JSX, syntax is crucial.
It's sunken cost fallacy, Stockholm syndrome and FUD.
<MyThing><div class="thing--contents">"Hello"</div></MyThing>
versus const div = document.createElement("div");
div.innerText = "Hello";
div.classList.add("thing-contents");
const wrapper = thingFactory(div);
Aren't we? It just adds up very quickly is what I'm saying.Example using Lit and Template Literals:
html`<div class="thing-contents">Hello</div>`;
Example using only web components: shadow.innerHTML = `<div class="thing-contents">Hello</div>`;I was just saying that I do occasionally do things entirely by hand in Javascript with createElement, and it works for a quick thing but it is actually definitely a thing that warrents bringing in some alternative.
const div = e("div", {className: "thing-contents"}, "Hello")
Or with coffeescript div = e "div", className: "thing-contents", "Hello"
Or with coffeescript and simple Proxy wrapper: div = @div class: "thing-contents", "Hello"1. Doing "myElement.innerHTML = `...`" is sufficient for the low-hanging fruit that most jsx gets used for.
2. I also have a `Fluent()` function that returns an object with attrSet/attrRemove/classAdd/etc functions, which each also return the same object. It lets me do something like:
var el = Fluent('div')
.attrSet('disabled')
.classAdd('waves btn btn-small')
.idSet('MyNewElement')
.push(Fluent('div')
.attrSet('...'))
.attachTo(document.querySelector('#SomeParent');
So far, I'm not liking the second one much, and the first one is really hard to compose, but they're both useful for when you don't want a build-step. el = @div disabled: true, class: 'waves btn btn-small', id: 'MyNewElement',
@div ...Walks like an XHTML duck. Talks like an XHTML duck. It's an XHTML duck despite the JS interop and the lack of DTD preamble.
It makes the language substantially more complicated, with additional corner cases (e.g. className and htmlFor). For what I see as solely matter of (bad) taste (being used to XML syntax for defining elements, and abhorring extra backticks?).
The pseudo-HTML is not far from JSX in the hackiness, but at least it's embedded in HTML.
(Possibly relevant source/proof: my TSX-based library supports the HTML shortcut names just fine, like:
`class`: https://github.com/WorldMaker/butterfloat/blob/cb9498354a7fb...
`for`: https://github.com/WorldMaker/butterfloat/blob/cb9498354a7fb...)