Skip to content

when()

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"),
),
)