Live data from Hacker News

Show HN: Gomponents, HTML components in pure Go

gomponents.com

21–30 of 50 posts

Re: Show HN: Gomponents, HTML components in pure Go

#21

are event handlers possible? neither the Github repo nor the linked page showed an example of a button or form submission.

gomponents is just a glorified string builder, so it's more or less like writing HTML in Go that gets output from the server. So you put event handlers on your elements like you normally would, write scripts and include JS like you normally would, etc.

That said, there's gomponents-htmx [0] for easy integration with HTMX.

[0]: https://github.com/maragudk/gomponents-htmx

Re: Show HN: Gomponents, HTML components in pure Go

#22

are event handlers possible? neither the Github repo nor the linked page showed an example of a button or form submission.

It looks like this is focused on server rendering HTML, no client-side runtime or anything like that. I don't see any used of a `Script()` function or similar in the example apps, though you could always chunk some JS in a public directory and link it in the HTML. They do have a starter example that uses HTMX. That'd be my go-to as well for a tool that's sticking with server rendering HTML.

Yep, this exactly. And the starter kit mentioned is here, for anyone curious: https://github.com/maragudk/gomponents-starter-kit

Re: Show HN: Gomponents, HTML components in pure Go

#25
Hey all! Sorry for being late to the party. I posted this on HN earlier this week, and only just saw it pop up here. I'll hang around today and try to answer questions and comments. :) I'm in the CEST timezone.

You may also be interested in the "go podcast()" episode I was in earlier this week, talking about gomponents with Dominik: https://gopodcast.dev/episodes/045-gomponent-with-markus-wus...

Re: Show HN: Gomponents, HTML components in pure Go

#26
post #14

While acknowledging the use case of "the designer who doesn't know how to program" and the desirability in some sense of separating logic from data, if I am going to slam together some HTML as a programmer, with no "non-programmer" designer in sight, I tend to slap together a local version of templates like this if I can't find a good one available. The reason is, if I'm going to mix logic and presentation anyhow, wh…

I'm really curious whether this will hold true in the future. I think the whole JS/React/JSX ecosystem really got a lot of people over to the programming side from "just" writing HTML and CSS, and I'm wondering whether this could happen for something like Go, too.

Now that the pendulum has swung in favor of rendering HTML server-side again and sprinkling Javascript on top, I sense a lot of interest in different ways of doing things than the default backend + JSON HTTP API + React/Vue frontend stack. And because Go is such a relatively simple language, maybe purely frontend/design-focused developers can pick it up and start writing HTML components with it?

(It helps that my preferred style of putting all HTML components inside a package called "html" inside the Go module/app could neatly containerize newcomers, to not scare them off with all the other stuff that is a Go app.)

Re: Show HN: Gomponents, HTML components in pure Go

#27

are event handlers possible? neither the Github repo nor the linked page showed an example of a button or form submission.

If you mean “action=/foo” for a “form” tag, there is an “Action” attribute: https://github.com/maragudk/gomponents/blob/main/html/attrib...

The OG event handler. :D

Re: Show HN: Gomponents, HTML components in pure Go

#29
post #23

Looks cool. There is also Templ[1] that does something similar, though uses codegen. I wish there is an equivalent of Storybook for these things though, it would be really nice! [1] https://templ.guide/

What's Storybook? Could you elaborate?

Not the OP but I think he meant the one at https://storybook.js.org
Post reply on HN