Skip to content

Render content conditionally based on a reactive condition.

function when(
condition: () => boolean,
then: () => WhisqNode | string | null,
otherwise?: () => WhisqNode | string | null,
): () => Child
ParamTypeDescription
condition() => booleanReactive condition
then() => WhisqNode | string | nullRendered when true
otherwise() => WhisqNode | string | nullRendered when false (optional)
import { signal, when, div, p, button } from "@whisq/core";
const loggedIn = signal(false);
div(
when(() => loggedIn.value,
() => p("Welcome back!"),
() => button({ onclick: login }, "Sign In"),
),
)
  • match() — multi-branch conditional for 3+ cases with a fallback.
  • each() — iterate a reactive array (use together for list-plus-empty-state shapes).
  • Conditional Rendering guide — narrative arc of whenmatch → inline ternary.

Docs current to v0.1.0-alpha.9 . All releases →