Hacker News new | ask | show | jobs
by zodiac 3362 days ago
It really isn't a template language as the term is commonly used. If you feel so strongly about the weird syntax you can write equivalent code in javascript syntax instead.

  return React.createElement(
    button,
    { className: "square", onClick: () => this.setState({value: 'X'}) },
    this.state.value
  );
If you think your code is written in a template language, then the code I just wrote must also be written in a template language (with different syntax).
2 comments

That's not a good thing.

I want to write this, and have it actually be HTML:

    <div>
        <div>
        </div>
    <div>
I like HTML.
Though I personally can tolerate JSX, maybe you like SGML templating [1] which uses native markup mechanisms such as entity references for fully HTML-aware and injection-free templating.

[1]: http://sgmljs.net/docs/templating.html

Disclaimer: my project, and SGML is most certainly not a "lightweight template engine" by any measure

Same here! Try VueJS. Especially Vue Components as they wrap up HTML template and JS code. Vue creates the render function from the HTML template, so no mucking around with jsx. Personally I want to think in "HTML" with JS secondary.
I love VueJS.
That looks like JavaScript. Yes, of course you can use that - but which react projects do it that way? It seems this is mostly pulled out when people go... ewwwwwwww, stinky...

Most use the html+javascript language which is compiled and then spits out JavaScript and html. This is pretty much identical to PHP - which is a preprocessor template language.

Anyway, facebook says it reminds me of a template language, so I'll believe them.

> Most use the html+javascript language which is compiled and then spits out JavaScript and html. This is pretty much identical to PHP - which is a preprocessor template language.

No, it spits out javascript (the exact same javascript that I wrote), which returns shadow DOM trees (which are javascript objects), which the renderer looks at to modify the actual DOM.

Also not sure what you mean by "looks like" javascript. It's clearly javascript - just a function call with 4 arguments.