Skip to content

<Show> / when

Render content when an expression is truthy.

import { Show } from "rvx";

<Show when={someCondition}>
    {() => <>Hello World!</>}
</Show>
import { when } from "./rvx.js";

when(someCondition, () => "Hello World!")

Truthy Results

Truthy condition results are passed to the child callback as the first argument.

const message = $("Hello World!");

<Show when={message}>
    {value => <h1>{value}</h1>}
</Show>
const message = $("Hello World!");

when(message, value => e("h1").append(value))

Fallback

A function to render fallback content can be specified as the else property.

<Show when={message} else={() => <>No message.</>}>
    {value => <h1>{value}</h1>}
</Show>
when(message, value => e("h1").append(value), () => "No message.")