Skip to contents

Renders the yes branch when condition is TRUE, and otherwise (if provided) when it is FALSE. The active branch is fully mounted and the inactive branch is destroyed.

Usage

When(condition, yes, otherwise = NULL)

Arguments

condition

A reactive expression that returns a logical value.

yes

A 0-arg function returning the tag tree to render when the condition is TRUE.

otherwise

An optional 0-arg function returning the tag tree to render when the condition is FALSE. With NULL, nothing mounts on the false branch.

Value

A irid control-flow node.

Details

Conceptually a fixed-shape binary specialization of Match(): When(\() cond, \() yes, \() no) is equivalent to Match(\() cond, Case(TRUE, \() yes), Case(FALSE, \() no)).

Bodies are 0-arg functions that return tag trees — not tag trees directly. When mounts and unmounts the active branch on transition, so each activation must construct a fresh tag tree (the previous branch's closures were torn down with its reactives). Reach for Match() when the branch needs to consume the dispatching value.