GX Framework
Props and children
Props are ordinary Go structs. Children are explicit node slots that let a component accept nested content without guessing how the caller wants to compose it.
Data goes in props
Use props for labels, flags, callbacks, and other values that describe the component. Keep the shape visible in the Go type so reviews can see what is required and what is optional.
type CardProps struct {
Title string
Tone string `gx:",optional"`
Children []gx.Node
}
func Card(props CardProps) gx.Node {
return gx.Element("section", gx.Props{"class": "card " + props.Tone},
gx.Element("h2", nil, gx.Text(props.Title)),
props.Children,
)
}
Children carry nested content
Children keep the caller in charge of the inner structure. Use them for body copy, lists, nested controls, and other content that should render in the order the caller wrote it.
See also Component functions and Nodes and render tree.