Comment by DaiPlusPlus
12 hours ago
> Why do people use JSX for e.g. blogs when HTML templating is built into the browser and they do nothing dynamic?
...but real HTML templating isn't built-in to HTML[1]. Its absence for these 30 years is as huge a mystery as why there's no combobox input element (combination textbox+drop-down) or <select>'s limitations.
[1] What I mean by this is that JS+DOM still has no simple way of escaping HTML in a string. It's insane.
To elaborate: if you have a some arbitrary strings (unsanitized user input): `headerText` and `firstParagraph` that you want to render to a HTML fragment like `<h2>{headerText}</h2><p>{firstParagraph}</p>` then the only real way of doing this safely is by using the (archaic and verbose) DOM Level 1 methods (document.createElement, textContent = 'text', etc) which somehow always turn what-should-be a 1-liner pure-function in any sane language to a 10-line function with side-effects (...and as it's 2025 then it will probably be async too).
When JS added support for template-literals, I was excited that this might mean an end to the embarrassing problem, but because it didn't ship with HTML-escaping it means it's useless for that purpose - unless you're going to go through the effort to implement a full "tagged template" with a parser function, which I assume would handle the DOM parts.
No comments yet
Contribute on Hacker News ↗