Component Get Nodes
Swap in a custom GetNodes function when a component's children can't be fixed at construction time.
Overview
Normally a component's children are whatever you Add to it. hlivekit.ComponentGetNodes wraps an l.ComponentMountable and instead calls a function you supply every time HLive needs that component's children. This is for the rare case where the child tree has to be computed fresh from something outside the component's own state.
Careful: the Tag Children rule still applies — this function is called many times, not just when it's time to render, and must be deterministic.
API
hlivekit.NewComponentGetNodes(name string, getNodesFunc func() *l.NodeGroup, elements ...any) *ComponentGetNodes— create the component. (Shortcut:hlivekit.CGN.)(*ComponentGetNodes).GetNodes() *l.NodeGroup— callsgetNodesFuncand returns its result.
Use case
A component that mirrors an external, shared data structure (say, a cache keyed by a request-scoped ID) where the source of truth lives outside the component and can change between renders. Recomputing the node tree from that source each time is simpler than keeping the component's own children in sync with it by hand.
Code sample
results := hlivekit.NewComponentGetNodes("search-results", func() *l.NodeGroup {
items := searchIndex.Query(currentQuery.Get())
nodes := make([]any, 0, len(items))
for _, item := range items {
nodes = append(nodes, l.NewTag("li", item.Title))
}
return l.Group(l.NewTag("ul", nodes...))
})