Skip to main content

when

Function when 

Source
pub fn when<P: Piece>(
    cond: impl Fn() -> bool + 'static,
    build_arm: impl Fn() -> P + 'static,
) -> When
Expand description

Reactive conditional subtree. The anchor is a layout-transparent group; the active arm lives in its own child scope, disposed on switch (§4.3).

A bare when builds nothing while the condition is false. Chain otherwise for the either/or case:

ⓘ
when(move || ok.get(), || label("Saved")).otherwise(|| label("Failed"))

Prefer a binding to a flip when both arms are the same widget with different content: label(move || if ok.get() { "Saved" } else { "Failed" }) keeps one native label alive and costs one setter call, where a when swap destroys and recreates native widgets.

Day API ↩ Guides· daybrite.dev