gomponents is amazing! I find the abstractions just right. it now looks possible that I can port my minimalistic bun/deno setup with htmx to go.
I found "gow" watcher that allows auto-restart of the development webserver when go code was changed. And I'm using "hx-refresh" header paramter and "hx-trigger='every 250ms'" to have a simple polling browser refresh.
it also integrates well with tailwind css. you can use tailwind vscode extension and define a custom "classRegex" for gomponents "Class(...)" function.
I needed to write a custom `Classes()` function that allows me to have conditional classes like `clsx()`. it's a bit hacky, but I like the simplicity.
func Classes(nodes ...g.Node) g.Node {
var classes []string
for _, node := range nodes {
if node != nil {
var builder strings.Builder
_ = node.Render(&builder)
c := builder.String()
c = strings.TrimLeft(c, " class=\"")
c = strings.TrimRight(c, "\"")
classes = append(classes, c)
}
}
return Class(strings.Join(classes, " "))
}
the runtime panics for functions that use vararg for optional arguments and have an invalid number of arguments is probably an okayish trade-off. mixing attributes and children elements in the builder functions, I don't know if it's good or bad, but I like the simplicity; JSX and hyperscript-like functions separate tag, attributes, and children into three different parameters.edit: reformat and typos.