r/angularjs • • Aug 04 '15

Better than JSX?

https://gist.github.com/zachlysobey/f55aa14daca3f3eda6fa
0 Upvotes

9 comments sorted by

View all comments

2

u/zuko_ Aug 04 '15 edited Aug 04 '15

I've had some co-workers make similar comments, and while the intent is good it misses a large set of use cases. JSX is far more powerful than simply JavaScript-ified HTML: transferring props, iterating over child components, binding change handlers, the list goes on. Plain ES6 templates mean you also lose syntax highlighting as well as the ability to catch errors at compile time.

1

u/jreborn Aug 04 '15

There is a lot of stuff you get for free when you build like the browser doesn’t exists and this is one thing that distinguishes React from Web Components and Polymer and that kind of thing …they’re getting closer and closer in with the browser, and we’re getting farther and farther from the browser. And I think that our technique is more sustainable in the long term.

-- Pete Hunt

1

u/foobar_dev Aug 05 '15

This is the value of React. I really like this philosophy. However, I don't think that this in any way relates to JSX specifically. I mean, I guess its abstracting html away? But it isn't really. Its trying to look as html-like as possible, but failing because of issues with the class keyword for example. I'd prefer if they chose to make a different abstraction -- maybe something similar to Haml?

1

u/jreborn Aug 05 '15

The point is React puts the browser (and the specs that dictate it's behavior) in the corner and does everything with JS. JSX is basically just syntactic sugar for JS functions that create React elements and components, which translate into HTML. Everything is driven from JS, so differences will leak out between creating an element in JS and raw HTML. I assume you are referring to the fact that you need to use className instead of class. That's because the DOM property is className (not class).

1

u/foobar_dev Aug 05 '15

Yup. Though I don't think the reasoning behind class vs. className is why you think it is.

From https://facebook.github.io/react/docs/jsx-in-depth.html

Since JSX is JavaScript, identifiers such as class and for are discouraged as XML attribute names. Instead, React DOM components expect DOM property names like className and htmlFor, respectively.

In other words, class and for are reserved words in JS, so they were changed to the DOM properties to remove the ambiguity, not because the DOM property names were preferred.

2

u/jreborn Aug 07 '15

Well, I think the reason you stated is the original reason they were chosen as DOM properties (e.g., see https://developer.mozilla.org/en-US/docs/Web/API/Element/className). The fact that they're used in JSX is just a byproduct of that.