Htmx is better than ReactJS
mindaslab.github.io
mindaslab.github.io
The HTML and CSS are going to be the same. Any UI state or side effects you're managing with React has to be managed in your htmx endpoints, and stateful APIs have plenty of their own quirks. You're doing the same stuff!
I can certainly understand how modern JS frameworks are harder for someone without a non-framework JS background, since the frameworks are a pretty clear evolution of how JS based web applications have been built for many years. But suggesting that developers pick React to inflate head counts and calling it "the hell-stack" makes it hard for me to think the author is engaging in good faith.
Like for instance... Apple Integer BASIC was a GREAT technology if all you had was an Apple ][ with 16k of RAM and were writing programs that interacted with a single user via the keyboard and monitor. If you have an array of hosts serving a web app and it's persistence tier up in someone else's datacenter, Apple Integer BASIC would not be my first choice.
But HTMX with it's conflation of presentation and business logic would also not be my first choice.
That's a rather wild interpretation (to put it midly).
You have compared things on subjective terms; i.e. about BASIC being better on a limited old Apple. But that's not the same as how some technologies are objectively better or worse than others.
I'd have understood if you were comparing things on the measure of engineering tradeoffs - but instead you speak in absolutes about the 'betterness' of a technology that you do not prefer, over one known to be slow and bloated (ReactJS). That seems questionable.
Also, there's nothing in the statement "different technologies aren't inherently better or worse than other technologies" which requires it be interpreted in isolation or to require it to be interpreted subjectively (or objectively.)
Sometimes we have to deal with the ambiguity of natural language.
I'm only half joking here, as that does seem to be one of the main reasons Facebook uses it. Another factor is that they write their backend in php.
Less tongue in cheek, why do you think that HTMX mixes presentation and business logic? Are you imagining we put business logic in the templates?
Hack is the language, not PHP.
But if you're looking for PHP + HTMX + components with no js ... I built a framework for it: https://framework.getswytch.com/
Have you seen React??
Htmx is just html attributes... that's it. If you want to mix things in your controllers, go ahead. But in my humble experience, the only way to write React components is to mix logic with presentation.
i don't view htmx as "better" than react. htmx extends HTML as a hypermedia and makes a lot of more advanced UX patterns available within it. This makes HTML a viable option for a larger set of problems than most web developers would suspect today.
However, hypermedia has fundamental limitations due to the trade-offs it makes. So there are still times when something more sophisticated, such as React, will be the better approach.
I have written an essay on when hypermedia is appropriate and when it isn't here:
https://htmx.org/essays/when-to-use-hypermedia/
There are times when htmx is going to be very successful when compared to react, such as here:
https://htmx.org/essays/a-real-world-react-to-htmx-port/
But that is not every time. And in that example they still used StimulusJS for "islands of interactivity" within the application.
I recognize that a lot of htmx users really dislike React, in particular, and, frankly, I'm not a huge fan of it myself. However I would prefer a more balanced take on the situation in general, and that software developers focus on the underlying ideas (hypermedia, HATEOAS, the uniform interface) rather than the specific tools. (I will note that there are other great hypermedia oriented JS libraries out there such as unpoly, hotwire and livewire)
Finally, if you've read this far, we have recently released our book on hypermedia systems:
what's the best (most open) place to offer an epub edition?
you can also go to the book-on-one-page:
https://hypermedia.systems/hypermedia-systems/
and print it as a PDF if you'd like
- Author, who is a rails backend developer, got a job where they used rails as a back-end, and react for front-end
- The author has strong backend skills, and strong html skills, but actively avoids javascript, and hates React
- Author tried to learn react for a year, but wasn't successful.
I think this quote sums it up properly:
> ReactJS takes this dirty imperfect, embarrassing JavaScript and makes it more dirty, imperfect and embarrassing. It’s a struggle for anyone who wants to write clean code to come to terms with the messiness of React.
This reads a lot more like a pity-party than a critique of any library or framework. I think during interviews, being a lot more honest about shortcomings can really help you understand if you're going to be doing the job you want to do. The author could have been really up front with "I like Rails, I like what it comes with, but I don't like javascript." Especially in today's web tech stacks, I think mentioning where you stand with javascript is pretty important. Most of the web contracts I have want some fancy javascript somewhere.
For those looking for a more in-depth critique of react, this article looks good: https://www.zachleat.com/web/react-criticism/
Although that focuses more on the objective legal and performance issues, if anyone can recommend something focusing more on architectural and developer ergonomics issues I'd love to see it.
But, just browsing around the web, I noticed that my experiences don't match the criticisms: Amazon is fast, Mastodon is fast, Twitter is (still) fast although a bit flickery, HackerNews loads slower than TheVerge for some reason. JetBrains Space is fast, Jira is a disaster. Static sites like GitHub and GitLab have been testing my patience recently - I wish GitLab was an SPA. The React pages that feel slow are often just poorly designed (momondo.com) or load ten times as much data than React could be responsible for (booking.com, icloud.com).
Admittedly, I'm not in a lab. I have content blockers, a fast computer and decent internet. But personally, I don't see a significant correlation between the framework and the perceived speed. Other aspects, such as the design of loading states seem more important.
There are cases where a bicycle is much more appropriate.
There are cases where a truck is much more appropriate.
These technologies are more complementing than competing.
https://htmx.org/essays/when-to-use-hypermedia/#hypermedia-a...
My understanding on why Rails is falling a bit out of favor is that it presumes a webserver? You can get a lot of mileage with a static asset based frontend.
I suppose the same problem largely lands for "components." Especially as you get related components?
Everything else feels pretty unproductive with a relational DB. Rust with sqlx is pretty nice and you get a very typesafe system but very slow to write.
I've started to use Htmx when I want to "sprinkle" some interactivity to the website, nothing big. It's similar to StimulusJs, same purpose.
I would use React (actually I don't use React anymore) when I want to build a full blown dashboard that rely on data from somewhere.
We've seen React going through massive changes lately that changed its image from being a "lightweight" library you can progressivly include to your webapp or website to acting like a web framework.
The new React docs even suppressed the option to use Vite and instead pushed the idea of using Nextjs instead which is quiet telling to how the React Team wants their library to be used.
It worked fine for simple use xases, but it was someone brittle and began to fail as soon as you wanted more than basic interactivity.
Honestly, intercooler.js aka htmx always seemed to be the worst of both worlds to me: You get back the heaps of redundant, uncacheable HTML fragments from the pre-SPA days, but you also take the dependence on javascript, unpredictable page behaviour and invisible page state from SPAs.
(Example: htmx now has websocket support - that is, as long as each server-to-client message is an html fragment. Have fun writing a basic websocket chat app and echoing back the entire chatlog including UI and formatting every time someone says something)
Why would you want that?
No, you just append.
I am somewhat amused that people think the latest / greatest technology is super-new. And I think you hit on that... HTMX definitely "rhymes" with some bits of old-tech. When I was at Amazon some of our devs were floundering trying to figure out how to estimate capacity requirements for some random app they were working on. So I brought in my System 370 Capacity Planning Guide from 1978 and it made a surprisingly decent high-level introduction to how to think about planning in the cloud.
Top notch review
In my preferred template language, jinja2, you'd write a macro. https://jinja.palletsprojects.com/en/3.0.x/templates/#macros
(defn some-component [{:keys [class]} & children]
[:div {:class (str "some-component-wrapper" class)}
[:h1 "Hello World"]
children])good ide support these days too between emacs, intellij, and vscode.