Wednesday, May 31, 2023

htmx

I've seen a bunch of different posts talking about htmx and how good it is.

I've mainly not listened to those articles until I read this one. This makes some of the hype around htmx click.

All HTMX does, is make the browser better at hypermedia by giving us more options regarding what can trigger an HTTP request and allowing us to update a part of the page rather than a full page reload.

So basically you can send any kind of HTTP request (GET, POST, PUT, DELETE) based on standard events (click, submit, mouseover) on any HTML element.

And the response you'd usually expect from the server (if we're using htmx in its intended form) is HTML that replaces some part of the page.

So rather than doing a full page refresh we're just updating part of the page with fresh HTML.

In the React scenario here it would be a useState() dispatch that would trigger a re-render when the state updates. This would also only update part of the page.

React might not need to send a network request (in this case) whereas htmx does but I think that's okay. Leaning on the server more is a good thing IMHO.

The simplicity of htmx is really captivating and I can see it making so much sense it a lot of use cases.

I've personally only tried out a few of its features but it's refreshing after doing years of pure React.