GX Framework
Component functions
A GX component is a Go function that returns gx.Node. Programmers use
component functions when they want a reusable building block that stays readable as
plain Go.
Keep composition explicit
Component functions are the point where the render tree becomes ordinary Go composition. You can call helper functions, branch on values, and return a node tree that other components can reuse.
func Panel(title string, body gx.Node) gx.Node {
return gx.Element("section", gx.Props{"class": "panel"},
gx.Element("h2", nil, gx.Text(title)),
body,
)
}
Where this sits in the model
The function itself does not need to know whether the caller later renders HTML, mounts the tree into a host, or inspects the output in tests. It just returns a node tree that other GX layers can consume.
See also Props and children and Nodes and render tree.