3 ms·
Then use JSX without React?
by notpushkin 1y ago
Then use JSX without React?
- hombre_fatal 1y agoWhat do you mean? JSX compiles to jsx(“div”, props, children) function calls so you need a runtime (which can be small) to render that into strings. At which point, who cares if you’re using react to do it? It’s a good zero dep implementation of a jsx fn.
- notpushkin 1y agoYeah, but this function needn’t run in the browser. Just generate HTML with it and save into a file! (I don’t have a link to npm handy, but I’m sure there’s a library that can do that already.) Alternatively, you can use Astro with React components, which will render them using React-DOM, but save them as static HTML by default (you can still choose some components to be hydrated, though).
- ne8il 1y agoThe article in question is specifically about using Next.js to do what you are saying (generate static HTML files from a set of React components). He also mentions using Astro for it.
- notpushkin 1y agoGood point, though the article mostly discusses static site generation (no server-side JS) and I think we can take it a step further and have no runtime / client-side JS as well. Next.js does usually have the runtime part, but I imagine it’s not too hard to disable (or you can strip all JS from the output). Astro, like I mentioned, strips JS by default (from island components, not from .astro components, though you can usually use those without any client-side JS, too). It is kinda roundabout way of generating HTML from JSX though.