If you’re using htmx, I highly recommend an HTML generation technique in your backend that lets you easily componentize in the same way as you can with React. Eg, extracting common pieces of HTML markup into functions much like React components.
The reason is that htmx requires a certain amount of flexibility in the HTML generated by the backend. Eg, you need to be able to generate a certain piece of HTML markup and put a <title> tag immediately adjacent to it in some situations, and not in others. (Htmx updates the page title when it finds a <title> tag at the top level.)
This kind of flexibility is difficult with traditional string-based templating engines, but trivial with language-embedded HTML libraries.
Eg, if your backend is in JS then a tagged template literal function like https://github.com/WebReflection/uhtml-ssr
If it’s a Go backend then a library like https://www.gomponents.com/
If it’s Scala then ScalaTags. And so on, you get the picture. The point is that a language-embedded system allows you to use the full power of your language to build abstractions and components, which htmx really benefits from.
Agreed, but uhtml-ssr looks a bit dated. If you want a html tagged template literal lib with no dependencies, see for example:
implementation: https://github.com/mastrojs/mastro/blob/main/src/core/html.t...
docs: https://mastrojs.github.io/docs/html-components/
For my Python backend I'm having success with JinjaX https://jinjax.scaletti.dev/
You can also use jsx on the backend. React has renderToStaticMarkup, but you probably want to use one of the jsx libraries written specifically for the backend.
You can use JSX but tagged template literals are supported out of the box by JS runtimes, so you wouldn’t need to add a build step.