Skip to main content

Overview

The Show component provides a declarative way to conditionally render content with support for fallbacks. It offers two control modes: root-controlled and content-controlled rendering.

Import

Component Parts

Show.Root

The root component that controls conditional rendering

Show.Content

Defines content to show when a condition is met

Show.Fallback

Defines fallback content when no condition is met

Show.Otherwise

Alias for Show.Fallback

Show.Root

Root-Controlled Mode

false | TWhen | null | undefined
required
The condition to evaluate. When truthy, renders children. When falsy, renders fallback.
React.ReactNode | ((value: TWhen) => React.ReactNode)
required
Content to render when the condition is truthy. Can be a render function that receives the truthy value.
React.ReactNode
Content to render when the condition is falsy.
'root'
default:"'root'"
Specifies root-controlled mode.

Content-Controlled Mode

'content'
required
Specifies content-controlled mode where children determine what renders.
React.ReactNode
required
Must contain Show.Content components with when props.
React.ReactNode
Content to render when no content condition is met.

Show.Content

false | TWhen | null | undefined
required
The condition for this content block.
React.ReactNode | ((value: TWhen) => React.ReactNode)
required
Content to render when this condition is truthy.

Show.Fallback / Show.Otherwise

React.ReactNode
required
Fallback content to display.

Usage Examples

Basic Conditional Rendering

With Fallback

Using Show.Fallback Component

Content-Controlled Mode

Multiple Conditions

Static Children

Nested Conditions

Boolean Conditions

Array or Object Checks

First Match Wins

Notes

  • In root-controlled mode with a render function, the function receives the truthy value of when
  • In content-controlled mode, the first Show.Content with a truthy when prop is rendered
  • You cannot use both the fallback prop and Show.Fallback component simultaneously
  • Show.Otherwise is an alias for Show.Fallback for semantic clarity
  • The component narrows types when using render functions with TypeScript
  • Content-controlled mode requires at least one Show.Content child