Lists
Reactive collections with stable identity for diffing.
Gova provides three list primitives. Pick List when you want explicit
control, ListOf when each item carries its own identity, and ForEach (or
ForEachIndexed) when the slice is not reactive.
List
List reads the slice from the given state and calls renderFn(i, item)
for each element. The keyFn produces a comparable identity that the
reconciler uses to diff item moves and removals.
ListOf
ListOf infers the key from the element. Resolution order:
- If
T(or*T) has anID() Kmethod, the method is called. - If
Tis a struct with a field tagged`gova:"id"`, that field is used. - If
Tis a struct with an exportedIDfield, that field is used. - Otherwise the slice index is used as the key. This works but is less
robust under reordering; consider
Listwith an explicit key function.
Accessor resolution caches per element type, so the reflection cost is paid once per process.
ForEach and ForEachIndexed
Use ForEach for plain slices that do not come from a StateValue. The
result is a flat Group node that drops into any parent layout.
ForEachIndexed is identical except the render function also receives the
index, matching the old List signature for callers that do not need
reactive updates.
Identifiable interface
Implement this when you control the type and want ListOf to pick up the
identity by method rather than field. Both value and pointer receivers work.
DerivedList
Wrap a state whose value contains a slice to produce a *StateValue[[]T]
suitable for List or ListOf:
See Signals and derived values for details.