Skip to main content

Component | Conditionally Render

Conditionally render components based on an expression. Expressions are evaluated for truthiness.

const shouldRender = true

ui.cond(shouldRender === true, {
true: ui.text("It's true!"),
false: ui.text("It's false!")
})

In cases where either the true or false component is not provided, nothing will be rendered if the condition evaluates to that value.

API reference

Function signature

type Component = ReturnType<typeof ui.textInput> | ReturnType<typeof ui.button> | /* more components */ | ReturnType<typeof ui.stack>

ui.cond(
condition: any,
options: Partial<{
true: Component,
false: Component
}>
)

Parameters

condition

required any
The condition to evaluate. The condition will be evaluated for truthiness

properties.true

optional Component
The component to render if the condition evaluates to true. If not provided, nothing will be rendered.

properties.false

optional Component
The component to render if the condition evaluates to false. If not provided, nothing will be rendered.