TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Alternatives to JSX

104 pointsby bloomcaabout 6 years ago

22 comments

hn_throwaway_99about 6 years ago
Wow, after reading this, I&#x27;d be surprised if anyone could come away with the conclusion &quot;Yeah, that&#x27;s better than JSX.&quot;<p>I think the general distaste for JMX is that it &quot;feels&quot; backwards initially: it mixes in HTML snippets within code, while many people are used to template files, which are mainly markup with small bits of &quot;presentational&quot; code injected.<p>But once you realize and really understand that JSX is just shorthand for javascript calls (and the article does a good job of explaining this), you hopefully eventually reach an &quot;Aha!&quot; moment of thinking of JSX in terms of underlying component creation. That&#x27;s what happened to me, anyway,.
评论 #19244132 未加载
评论 #19243786 未加载
评论 #19243710 未加载
评论 #19243626 未加载
评论 #19243669 未加载
评论 #19243750 未加载
评论 #19244485 未加载
评论 #19244102 未加载
评论 #19243650 未加载
评论 #19243981 未加载
评论 #19245544 未加载
bennypowersabout 6 years ago
Why JSXBelPack when you can<p><pre><code> import { html, render } from &#x27;https:&#x2F;&#x2F;unpkg.com&#x2F;lit-html&#x27;; const benefitTpl = ({name, desc}) =&gt; html` &lt;dt&gt;${name}&lt;&#x2F;dt&gt; &lt;dd&gt;${desc}&lt;&#x2F;dd&gt; `; render(html` &lt;lit-rocks&gt; &lt;dl&gt;${benefits.map(benefitTpl)}&lt;&#x2F;dl&gt; &lt;&#x2F;lit-rocks&gt;`, document.body) </code></pre> And updates are fast without any VDOM overhead.
评论 #19247842 未加载
评论 #19247901 未加载
评论 #19247320 未加载
评论 #19249796 未加载
dazhbogabout 6 years ago
I used to be really sceptical about JSX, 1 extra transp. step, anorthodox use of xml in JS, etc.<p>Having been using it for the past 3-4 years I think its an above agerage elegant solution when it comes to templating solutions.
cdaringeabout 6 years ago
Pug is a worthy mention. <a href="https:&#x2F;&#x2F;github.com&#x2F;pugjs&#x2F;babel-plugin-transform-react-pug&#x2F;blob&#x2F;master&#x2F;README.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pugjs&#x2F;babel-plugin-transform-react-pug&#x2F;bl...</a> wasn&#x27;t mentioned
cygnedabout 6 years ago
What really bugs me about JSX is the complexity it introduces to the build pipeline - which might be fine for senior developers, but I regularly see junior developers struggle with configuration and errors.
评论 #19245357 未加载
评论 #19244312 未加载
pier25about 6 years ago
The fact that front end has to deal with 3 different languages (JS + HTML + CSS) is a problem nobody has completely solved.<p>These days the solution usually falls into 3 camps:<p>1) Write everything in JS like React.createElement or Mithril. No build setup but a pain to use.<p>2) JSX. Requires a build setup which might become complex as the project grows.<p>3) Templates. Probably the less elegant of all 3 but the most pragmatic and easy to use.<p>Someone attempted to solve this and created a new language called Imba. It&#x27;s like a mutant Ruby with HTML that compiles to JS.<p><a href="http:&#x2F;&#x2F;imba.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;imba.io&#x2F;</a><p>It has a lot of productivity benefits compared to previous attempts at solving the same problem, but goddammit it&#x27;s ugly.
评论 #19246396 未加载
评论 #19247562 未加载
nojvekabout 6 years ago
We use virtual jade at work. It works with most virtual doms that use some form of h(name, attrs, children) calls.<p>We have webpack hot reloading so we can work on UI without any page refreshes.<p>It’s been very productive. I love the brevity of jade&#x2F;pug. Jsx feels like a lot of boilerplate braces and ending tags.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tdumitrescu&#x2F;virtual-jade" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tdumitrescu&#x2F;virtual-jade</a>
评论 #19246868 未加载
maccoabout 6 years ago
I would advice against using JSX alternatives. I come from a Clojure background and I like the ijk solution to just use an array to represent the virtual dom.<p>But still I would recommend using JSX because it the &quot;standard&quot;. Every documentation and problem solution you find on the internet is written with JSX. Using a JSX alternative will make debugging much harder for you.
SkyPuncherabout 6 years ago
HTM actually looks pretty intriguing to me.<p>One thing I like about JSX is that it looks and feels like HTML.<p>For me, that has two huge benefits:<p>1. It narrows the dissonance between the code I&#x27;m writing and the actual structure that will be rendering into the DOM. I find it much easier to write and debug when I don&#x27;t have translate between some JS factory function and the actual DOM implementation.<p>2. It&#x27;s almost pure HTML. Sure I&#x27;ll have to change class to className and update some other tags. Generally, though, if something works in HTML, it&#x27;s little fuss to do in JSX. With tools like JSX, I can write in a single templating language across all of my software.
评论 #19246475 未加载
keymoneabout 6 years ago
i&#x27;m surprised hiccup was never mentioned. ofc it&#x27;s not for pure JS but there&#x27;s this thing - <a href="https:&#x2F;&#x2F;github.com&#x2F;lantiga&#x2F;react.hiccup" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lantiga&#x2F;react.hiccup</a> though i never tried and don&#x27;t know how well it works. still interesting.
评论 #19245317 未加载
oorzaabout 6 years ago
There&#x27;s also kotlin-react which let&#x27;s you write React in Kotlin in a Kotlin DSL which looks exactly like your first imagination probably suggests: <a href="https:&#x2F;&#x2F;github.com&#x2F;JetBrains&#x2F;kotlin-wrappers&#x2F;tree&#x2F;master&#x2F;kotlin-react" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;JetBrains&#x2F;kotlin-wrappers&#x2F;tree&#x2F;master&#x2F;kot...</a><p>It&#x27;s also a pretty impressive demonstration of the typesafe flexibility of Kotlin&#x27;s DSL support, but that&#x27;s another conversation.
ertucetinabout 6 years ago
ClojureScript + Reagent
评论 #19245102 未加载
评论 #19244154 未加载
评论 #19244939 未加载
drooblesabout 6 years ago
A point to the discussion of whether JSX is preferable or not to a programmer, most React projects with JSX I&#x27;ve worked on has had the awesome bonus of a designer who knows markup&#x2F;css to be able to add layouts to our web and React Native projects. Just wanted to throw that out there as a plus to JSX. I don&#x27;t think the designer could follow hyperscript very well.
fnordsenseiabout 6 years ago
There&#x27;s also HDOM, part of the larger Umbrella collection of libraries: <a href="https:&#x2F;&#x2F;github.com&#x2F;thi-ng&#x2F;umbrella&#x2F;tree&#x2F;master&#x2F;packages&#x2F;hdom" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thi-ng&#x2F;umbrella&#x2F;tree&#x2F;master&#x2F;packages&#x2F;hdom</a><p>Purported benefits from the readme:<p>- Use the full expressiveness of ES6 &#x2F; TypeScript to define user interfaces<p>- No enforced opinion about state handling, very flexible<p>- Clean, functional component composition &amp; reuse, optionally w&#x2F; lazy evaluation<p>- No source pre-processing, transpiling or string interpolation<p>- Less verbose than HTML &#x2F; JSX, resulting in smaller file sizes<p>- Supports arbitrary elements (incl. SVG), attributes and events in uniform, S-expression based syntax<p>- Supports branch-local custom update behaviors &amp; arbitrary (e.g. non-DOM) target data structures to which tree diffs are applied to<p>- Component life cycle methods &amp; behavior control attributes<p>- Suitable for server-side rendering and then &quot;hydrating&quot; listeners and components with life cycle methods on the client side<p>- Can use JSON for static components (or component templates)<p>- Optional dynamic user context injection (an arbitrary object&#x2F;value passed to all component functions embedded in the tree)<p>- Default implementation supports CSS conversion from JS objects for style attribs (also see: @thi.ng&#x2F;hiccup-css)<p>- Auto-expansion of embedded values &#x2F; types which implement the IToHiccup or IDeref interfaces (e.g. atoms, cursors, derived views, streams etc.)<p>- Fast (see benchmark examples)<p>- Only ~6.2KB gzipped
mmmeffabout 6 years ago
Awesome article. I appreciate the lack of bias. Thanks for writing this, OP. It&#x27;s good to keep an eye on the horizon for potential alternatives to tech we use day in day out, but it looks like we&#x27;re still on solid ground with JSX so no need to switch :)
fromalexabout 6 years ago
There is also a babel-transform for pug[1]. It works quite well as JSX replacement. Not having any endig tags can be quite beneficial when reformatting stuff.<p>Paired with Tachyons (best atomic CSS lib) you get superpowers and can write code like<p><pre><code> const someComponent = () =&gt; pug` ul.p2.f3 Some list li.red Some text li.pink Some more` </code></pre> [1] <a href="https:&#x2F;&#x2F;github.com&#x2F;pugjs&#x2F;babel-plugin-transform-react-pug" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pugjs&#x2F;babel-plugin-transform-react-pug</a>
jayar95about 6 years ago
I think a lot of readablity issues with jsx are caused by the amount of logic react devs will put in their markup. It&#x27;s painfully reminiscent of old-school PHP templating
batisteabout 6 years ago
My problem with JSX is that if you introduce a DSL, why would you limit it to basic function calls&#x2F;expressions?<p>I created a small language to demonstrate what I mean <a href="https:&#x2F;&#x2F;github.com&#x2F;batiste&#x2F;blop-language" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;batiste&#x2F;blop-language</a>
评论 #19247484 未加载
oldboyFXabout 6 years ago
I was a bit apprehensive about JSX before quickly getting used to it. Now I love it.<p>The only decision I dislike is renaming class to className. Why not klass, cls, cs... anything shorter.<p>ClassName is simple to understand but adds a lot of clutter to component files.
评论 #19248098 未加载
itsbitsabout 6 years ago
lit-html surely does a good job..<p>- ES6 string literals<p>- partial template rendering<p>are few cool features with it.
评论 #19247278 未加载
评论 #19246175 未加载
hardwaresoftonabout 6 years ago
If you read this article and thought Hyperscript might be something you wanted to try, please check out Mithril[0].<p>It&#x27;s an excellent project, pretty decently fast (checkout the js-framework-benchmark[1] code, or more specifically the results of round 8[2]) -- but is currently suffering from a lack of recognition. It&#x27;s the kind of project that absolutely doesn&#x27;t care about that kind of metric (as in, the team seems to be more focused on slow, steady improvement of the library rather than chasing stars on github), but I figured I should say something.<p>Shameless plug: I recently really wanted to contribute something (and kick the tires more) so I wrote an article that goes through replicating a simple mail design I saw[3] -- it might be a decent overview of what mithril is like to write (though I&#x27;m certainly not a mithril expert).<p>This brings me back to the point at hand -- as others have noted, in my opinion one of the best things about hyperscript is the straight-forwardness with which you construct the render function. I&#x27;m not convinced it&#x27;s necessary to segregate stateless&#x2F;stateful components -- and mithril is simpler in that it doesn&#x27;t introduce this dichotomy -- in the end there&#x27;s the render function, and that&#x27;s it. If you want to use state, go ahead -- if you don&#x27;t, then don&#x27;t. It&#x27;s the simplicity I&#x27;ve wanted from component frameworks (and mostly get with Vue) without any of the posturing&#x2F;looming complexity.<p>Also there&#x27;s the fact that you could write a completely vanilla es5 application with hyperscript (arguments whether you should or not aside) -- JSX is&#x2F;was revolutionary, but is basically required in practice, which often makes people jump into bed with webpack without thinking, and makes frontend development harder than it has to be.<p>[EDIT] - Another point for mithril is that it&#x27;s <i>self contained</i> -- routing and ajax calls some with the framework. When people these days talk about &quot;react&quot; or &quot;vue&quot; what they&#x27;re really talking about is react&#x2F;vue + react-router&#x2F;vue-router + flux&#x2F;vuex and some other odds and ends. Mithril is by far the simplest and most feature-complete of these frameworks despite being smaller (both conceptually and on-the-wire).<p>One of my only current gripes with Mithril is the lack of controllable subtree rendering (it isn&#x27;t as much of a problem in practice, but more me wanting to optimize early).<p>[0]: <a href="https:&#x2F;&#x2F;mithril.js.org" rel="nofollow">https:&#x2F;&#x2F;mithril.js.org</a><p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;krausest&#x2F;js-framework-benchmark" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;krausest&#x2F;js-framework-benchmark</a><p>[2]: <a href="https:&#x2F;&#x2F;www.stefankrause.net&#x2F;wp&#x2F;?p=504" rel="nofollow">https:&#x2F;&#x2F;www.stefankrause.net&#x2F;wp&#x2F;?p=504</a><p>[3]: <a href="https:&#x2F;&#x2F;vadosware.io&#x2F;post&#x2F;mithril-systemjs-and-rollup-getting-started-guide&#x2F;" rel="nofollow">https:&#x2F;&#x2F;vadosware.io&#x2F;post&#x2F;mithril-systemjs-and-rollup-gettin...</a>
评论 #19249820 未加载
评论 #19245705 未加载
austincheneyabout 6 years ago
I am getting a 404.
评论 #19243622 未加载