Skip to content

Conditions, lists and dynamic components

Render branches, preserve list identity and select imported components.

On this page

Conditional branches

xml
<Column>
    <If condition={busy}><Text text="Working" /></If>
    <ElseIf condition={failed}><Text text="Try again" /></ElseIf>
    <Else><Text text="Ready" /></Else>
</Column>

Place ElseIf/Else immediately after the preceding branch. Else must come last. These expressions belong to a State with the referenced fields.

The current block forms create physical Column wrappers. They are not transparent groups. Inrux does not yet accept Vue's v-if or the proposed attribute-first Inrux syntax.

Keyed lists

xml
<For each={rows.iter()} item="row" key={row.id}>
    <Text text={row.title.clone()} />
</For>

Use a stable, unique key for each sibling iteration. Reordering with the same key preserves the child's local state and retained identity. Removing a key unmounts the child. Adding that key later creates a new mount; it does not restore disposed state.

Avoid indexes as keys when items can move. Duplicate sibling keys produce an error. Ordinary unkeyed nodes use structural positions.

Dynamic selection

Import candidate components in <rust>. Use <Component :is={...} /> with a typed Rust expression returning a Node. There is no string-to-component registry.

xml
<Component :is={if state.editing {
    Editor::view(Editor::Props { title: state.title.clone() }, events, scope)
} else {
    Preview::view(Preview::Props { title: state.title.clone() }, events, scope)
}} />

This is a view fragment for imported stateless Editor/Preview components with a String title prop. Each candidate keeps its own Rust prop checks. Imported candidates remain in the compiled graph even when a runtime condition selects only one. Unimported custom tags fail with an import suggestion.

Read the component contract for mount behavior and architecture for build reachability.

Inrux · Built with Nuxt Content, IPEX, and Akaza UI.