Live data from Hacker News

JSX is no longer my friend

medium.com

71–80 of 144 posts

Re: JSX is no longer my friend

#71
In my opinion JSX is usable, and gets the job done. I have used it, and enjoyed it. However, my personal preference to write html is one that I think looks beautiful in comparison to template engines. Nicely enhanced by syntax highlighting, and perfectly pure in its structure. And with the most known syntax. It is the most simple and productive. It is: writing html in html itself. (I am describing my personal favorite, not saying that it should be the right way for everyone). I prefer frameworks that let me structure the html views of my projects, using declarative html.

In the same line, breaking things into components is best achieved, in my opinion, using web components. The syntax is a little muddy, due to all the html legacy cruft. But I find it better than the alternatives, for example react components. With web components, the great thing is that any styles and javascript functionality is scoped to the component. That allows for better separation of concerns in separated components. This is specially useful when you have components with functional styles: animations, transitions, etc.

After componetization is solved by web components, the problems with html in html boils down to mostly two things: generating multiple elements from some data, or setting data in elements based on some other data. For these things I prefer the syntax style of data binding and "repeaters". My favorite is polymer(https://www.polymer-project.org/1.0/). Example:

  
    
  
And the concern of repeating multiple elements is trapped in a component. In the example above, in . In general, when using this technique, data binding must not be abused, or the view becomes a mess.

Re: JSX is no longer my friend

#72
post #64

This needs to be prefaced: this argument is overdone. JSX is not hard to learn. It's an order of magnitude better than the hampered DSLs of handlebars or dust, and I'm concerned that any engineer is so scarred that learning it takes more than 5-10 minutes of RTFM. After all, TFM on JSX is all of 200 words or less [1]. I've been using JSX since React 0.4. React's greatest strength is its simplicity. You can read all o…

I'll know the answer to your question in a couple weeks. I'm working with web content developers who are very good with HTML and CSS but less familiar with JavaScript. We have a project using Mithril (architecturally like React) where we started out without MSX (exactly like JSX) but they think they're going to prefer MSX syntax so we've begun switching over.

I've worked with designers with limited JS knowledge on a JSX-free react code. There may have been a short learning curve, but it didn't seem to slow them down much at all, even really early on, certainly not after a week (at that point our codebase was coffeescript, so JSX wasn't a great option).

It may have helped that we converted an existing code base (so there was a lot of html-as-JS example material to see), and devs were around the corner for any questions - but in my experience, JSX did not appear to be relevant, not at all.

The only advantage jsx does have IME is that it enables copy-pasting real html (sometimes with minor alterations) into your source, and that's a mundane but constant minor boon. All the examples on the net are in html; and if e.g. you use browser dev tools to rearrange a page to look like you want it you can easily copy-paste that back into the source. I don't think that advantage is worth putting up with JSX for, but it's not irrelevant either.

Re: JSX is no longer my friend

#73
post #28

After many Medium posts of uninformed, not very insightful complaints about react and the state of JavaScript I am becoming inclined to just avoid Medium posts about JavaScript in general. Medium has become the analog to Tumblr posts for opinionated engineers to whine about things that don't really impact development in ways that matter. Really all this developer had to do was talk about Hyperscript in a positive way…

It's either this or "functional JavaScript" posts on my feed. Really, I've seen about ten "guides" about it in the past two weeks.

Re: JSX is no longer my friend

#74
Since about December 2015 I have been learning React-native for my android needs. While I had programmed extensively in Javascript in 2008 (dojo) -- I have forgotten number of things, and just essentially re-learning (and I had never done a production mobile app before).

I find JSX, at least within context of react-native is very useful.

I specifically like being able to have this 'duality' of a view for a Component.

JSX allows a custom component to viewed by outside as first-class citizen of an HTML mark up. But within the component -- it is a class with members, Eiffel-like preconditions for construction, and explicitly managed state.

I think React-folks got the separation between Presenters and Interactors exactly right.

I would not mind even more features where the state management relies on channels that are can contain Parent, children, and may be even 'peer' events. (something like clojurescript's CoreAsynch for the above 3 categories of events affecting states for a given component).

Re: JSX is no longer my friend

#75

This needs to be prefaced: this argument is overdone. JSX is not hard to learn. It's an order of magnitude better than the hampered DSLs of handlebars or dust, and I'm concerned that any engineer is so scarred that learning it takes more than 5-10 minutes of RTFM. After all, TFM on JSX is all of 200 words or less [1]. I've been using JSX since React 0.4. React's greatest strength is its simplicity. You can read all o…

I don't understand the OP's argument either.

I'm primarily a back-end dev with a bit of HTML+JS xp, and I had zero issues with JSX when I decided to use React for a small project. I didn't find JSX confusing at all, it took me about 10 mins to understand the syntax fully and the error handling was very explicit. I'm not experienced at JS frameworks (have used Knockout and that's about it) and I'm certainly not from a front-end or designer background, much the opposite actually.

What really bothered me at the time was that my code was messy and I was struggling to properly wire up the React components with my data model - thankfully I since discovered Flux and then Redux :)

Re: JSX is no longer my friend

#76
post #66
post #24

Earlier quoted context omitted.

Generally speaking, I do not recommend this pattern. My preference is to handle enumeration within a function, for example: {this.listItems(items)} Then, within a function implemented on the same component: listItems: function(items) { items.map((item) => { return {item.name} }); }

Is it just me, or is the return missing in the `function` (or am _I_ missing something :)? Not important of course, just pointing it out...

Good catch! I wrote that example in a hurry on my lunch break so I take accountability for the mistake.

Re: JSX is no longer my friend

#77
The decision to use JSX or not is really one of the least important decisions you need to make when writing a React application. It's essentially a style preference.

Personally I like JSX. It's nice having a special syntax that your editor and linter [1] can understand. And if you are part of the stateless/minimal-logic component camp then most of your components will look more like HTML/JSX with a little bit of JS interspersed than vice-versa.

[1] https://github.com/yannickcr/eslint-plugin-react#jsx-specifi...

Re: JSX is no longer my friend

#78
post #28

After many Medium posts of uninformed, not very insightful complaints about react and the state of JavaScript I am becoming inclined to just avoid Medium posts about JavaScript in general. Medium has become the analog to Tumblr posts for opinionated engineers to whine about things that don't really impact development in ways that matter. Really all this developer had to do was talk about Hyperscript in a positive way…

I think his points about new developers having to learn JS, React, and JSX all at the same time and then context switch between them in ways that aren't entirely clear was pretty spot on. I don't know how you draw that comparison without mentioning the shortcomings of JSX. Also with Hyperscript you're still building your markup directly in your Javascript, just using JS for it instead of JSX, not templates. Not sure…

The context switching argument is BS. That's just like complaining about 'context switching' when you have to use an hash/map/dict/object literal or a comment.

Re: JSX is no longer my friend

#79
I think the issue here is one of perspective. My thought would be that removing JSX and replacing it with other JS conventions may make it easier for new devs but I'm quite certain that now you've made your code base highly inaccessible for front end designers who just want to find the HTML hidden amongst all this code.

Re: JSX is no longer my friend

#80
should we write {0x68, 0x65, 0x6c, 0x6c, 0x6f} instead of "hello"?

joke aside, I think JSX does a great job to reduce the cognitive load, bridging codes as representation and its result.

Post reply on HN