A bit off-topic, and maybe it was just an example made without too much thought put into it, but I've noticed there seems to be a lot of people now who write button/links like this: My Button As far as I know that's technically invalid HTML. You can't have an as a child of a (or even the other way around.) I'm also ignoring the invalid type="submit" against the tag in the example button component in the post. I think…
> As far as I know that's technically invalid HTML. You can't have an as a child of a (or even the other way around.) I'm also ignoring the invalid type="submit" against the tag in the example button component in the post. It definitely feels weird to have anything other than text nodes inside , didn't realize it's actually invalid HTML. I used this approach mainly to have the button component behave as a link button…
Show HN: Use Go's HTML/template to write React-like code
71–80 of 96 posts
Re: Show HN: Use Go's HTML/template to write React-like code
#72Earlier quoted context omitted.
I love React too, but it pulls in a lot of dependencies and the dependencies need periodic maintenance. Sometimes you get the feeling that you're spending a significant chunk of your time not writing code but fighting with configs and dependency churn. Using Go's html/template definitely makes the UI feel dated because of re-rendering, but I rarely notice it in my side project. My next exploration is to use HTMX. I'm…
HTMX + React style server rendered components would solve 80% of the use cases for a modern SPA. Keep going! This is a breath of fresh air for many simpler applications.
Re: Show HN: Use Go's HTML/template to write React-like code
#73This is a nice approach I've followed myself before. It feels like common sense web development, just writing things in a way which allows them to be reused. A button will likely be the same on any page of the site, so make a button component. I don't think this is "React-like" though. Making components isn't specific to React. We've been doing that since ASP and probably earlier. Your views still need to know what c…
I 100% know it's a preference/style kind of thing, and I know the React/Node isn't perfect and comes with it's downfalls, but I whenever I have to code in anything other, I just miss the visual/mental model aspect of having your tsx code basically identical to your actual html. The mental load of going from this to func main() { component := Page{ Children: []Component{ Div{ Children: []Component{ Button{Name: "Test…
Re: Show HN: Use Go's HTML/template to write React-like code
#74Earlier quoted context omitted.
That's pretty much all it does. It reacts to an event, fetches from an URL, swaps the result from that URL in some part of the DOM.
Then does the server handling the requests needs to produce html fragments? If I request a page, how does it know to only serve / fetch / render the main content vs the full page? --- It seems like a lot of would be logic a real language has been moved to DSL and strings, i.e. https://htmx.org/docs/#swap-options `hx-on:htmx:config-request="event.detail.parameters.example = 'Hello Scripting!'"` Not a fan of this fad o…
HTMX sends some headers that help you identify the context, this way you can render just a portion of the HTML (e.g. just the partial of the "Todo" list in your "Todo App" homepage). You need some backend logic to handle that but still much less than a full blown JSON API would have.
They also have extensions that can diff and merge the DOM so even a full page load would replace just what changed, this way your backend is pretty much unaffected (you just end up serving more MBs).
There are other libs in this space by the way, like Unpoly and Hotwire, HTMX just got more mindshare.
> Not a fan of this fad of moving programming to embedded strings, also seen in lots of Yaml based systems
I absolutely agree. I had a comment thread with HTMX's creator about this, I feel like it's a bad idea to shove logic into that. He also created Hyperscript (https://hyperscript.org) so it's something he doesn't think is an issue.
In general I think it's pretty easy to rein that in. Just use HTMX to do most of the plumbing it's strong at (react, fetch, swap) and keep the logic server-side. In my experience that covers the vast majority of web apps. If I absolutely need more client-side logic I'd reach for a little JS code or create a Web Component.
Re: Show HN: Use Go's HTML/template to write React-like code
#75Earlier quoted context omitted.
Then does the server handling the requests needs to produce html fragments? If I request a page, how does it know to only serve / fetch / render the main content vs the full page? --- It seems like a lot of would be logic a real language has been moved to DSL and strings, i.e. https://htmx.org/docs/#swap-options `hx-on:htmx:config-request="event.detail.parameters.example = 'Hello Scripting!'"` Not a fan of this fad o…
Yes, the idea is to send HTML on the wire. HTMX sends some headers that help you identify the context, this way you can render just a portion of the HTML (e.g. just the partial of the "Todo" list in your "Todo App" homepage). You need some backend logic to handle that but still much less than a full blown JSON API would have. They also have extensions that can diff and merge the DOM so even a full page load would rep…
Re: Show HN: Use Go's HTML/template to write React-like code
#76[off-topic comment but somewhat relevant for anyone choosing a lang/ecosystem] I noticed that the syntax highlighting for the Go html/template examples in the article is incomplete. We're using Go html/templates on a new project (within a team that does a lot of React frontend & some Python) so this kind of project seems like it would really suit, but a massive bugbear has been the very poor IDE-level syntax highligh…
there are also projects that let you use HTML directly in Go like: https://www.gomponents.com/ (I'm currently using it in a side project and liking it so far, but I also just started)
Re: Show HN: Use Go's HTML/template to write React-like code
#77Re: Show HN: Use Go's HTML/template to write React-like code
#78Interesting. I am actually doubling down on building web apps in Go using mostly standard library, powerful templates and sprinkle in with a library such as Alpine JS. Seeing some success so far and it makes me so much happier knowing that I don't have to deal with node_modules BS (well may be except tailwind for css). I actually want to test the limits of how far one can go without using a JS framework like React/Vu…
What are the current frameworks or tools that are popular or recommended for building web applications with Go these days?
Re: Show HN: Use Go's HTML/template to write React-like code
#79Earlier quoted context omitted.
Once the major browser engines support it, it's de-facto legal. This also explains why there are so few alternative browsers. Writing a new browser that supports everything that happens to work in the major browsers is ridiculously hard.
The big innovation of the html5 spec was to specify how to handle all the “invalid” html states; recovery from user error is now part of the spec instead of wholly implementation specific.
Re: Show HN: Use Go's HTML/template to write React-like code
#80A bit off-topic, and maybe it was just an example made without too much thought put into it, but I've noticed there seems to be a lot of people now who write button/links like this: My Button As far as I know that's technically invalid HTML. You can't have an as a child of a (or even the other way around.) I'm also ignoring the invalid type="submit" against the tag in the example button component in the post. I think…
Once the major browser engines support it, it's de-facto legal. This also explains why there are so few alternative browsers. Writing a new browser that supports everything that happens to work in the major browsers is ridiculously hard.
thats madness. just because the browser allows it, doesn't mean you should do it.