Skip to Content

Show

Show renders its children when when is truthy, otherwise an optional fallback (or nothing).

Use it for a single optional branch. For multiple ordered branches, use Switch / Match.

Live Example

Optional user panel

Toggle between no user and a signed-in user to see the fallback versus narrowed children.

Please sign in to continue.

Import

import { Show } from "react-rsc-kit";

Props

PropTypeDefaultDescription
whenT | (() => T)requiredValue or getter; if truthy after resolution, children render.
childrenReactNode | ((value: Truthy<T>) => ReactNode)requiredStatic content or a function that receives the truthy when value.
fallbackReactNodeundefinedRendered when when is falsy. If omitted, renders nothing.

Usage

import { Show } from "react-rsc-kit"; function Greeting({ user }: { user: { name: string } | null }) { return ( <Show when={user} fallback={<p>Please sign in</p>}> {(u) => <p>Welcome, {u.name}</p>} </Show> ); }

Notes

  • Truthiness matches Match: values like 0, "", false, null, and undefined are not shown.
  • For several mutually exclusive branches, prefer Switch and Match.
Last updated on