Hacker News new | ask | show | jobs
by nikonikoniko 1473 days ago
I find that very interesting, I have the opposite reaction to JSX. Not wanting to use it has been one of the biggest reasons I have moved into using ClojureScript/Hiccup for front-end applications.

I find JSX extremely hard to read and work with and reason about.

1 comments

After you get a taste of the free world of hiccup/reagent where it's just vectors and maps to create HTML, its really hard to imagine going back to anything else. Being able to use the same programming language in your "HTML template" (which are just core data structures in a specific shape) as for the rest of your programming is just icing on the top.

Small example for people to understand the difference:

    // HTML & JSX
    <div id="person">
      <h1>Niko</h1>
    </div>
    
    // Hiccup
    [:div#person
      [:h1 "Niko"]]
I think the big differences don’t come out visually.

In JSX you might be struggling with expressing certain things, because JS has a statement expression syntax. So you have to circumvent that. In Clojure everything is an expression already.

In JSX you can manipulate components with HoCs. In Clojure it’s just data, no special ceremony needed.

On the client, if you’re using React, you might use hooks to keep travk of state, which are a special construct that don’t exist in JS. In Clojure, if you use something like reagent, you just use atoms, they have a special purpose implementation, but they look and feel like regular old atoms.

However I have to say, JSX and React are very productive even with those limitations, simply because the tooling around it is so good.

Hopefully the limitations around expressions in JS will go away at some point and JS will become properly expression orientated. There are already proposals for this, although they currently seem to be stalled.