when()
Render content conditionally based on a reactive condition.
Signature
Section titled “Signature”function when( condition: () => boolean, then: () => WhisqNode | string | null, otherwise?: () => WhisqNode | string | null,): () => ChildParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
condition | () => boolean | Reactive condition |
then | () => WhisqNode | string | null | Rendered when true |
otherwise | () => WhisqNode | string | null | Rendered when false (optional) |
Examples
Section titled “Examples”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"), ),)