Show is a React component that conditionally renders children based on an observable condition, with support for else fallback and value passing.
Usage
Signature
Props
A selector or observable whose value determines whether to show the children. Shows children when the value is truthy.Cannot be used together with
ifReady.Similar to
if, but specifically checks if the observable value is “ready” (not undefined, not a pending Promise). Useful for async observables.Cannot be used together with if.Content to render when the condition is false. Can be:
- A React node (JSX)
- A function that returns a React node
An observable to pass to the children function. When provided, the children function receives
$value.get() instead of the condition value.A wrapper component to wrap the rendered children. Useful for adding context providers or layout components.
The content to render when the condition is truthy. Can be:
- A React node (JSX)
- A function that receives the condition value and returns a React node
Returns
The rendered result based on the condition - either the children, the else content, or the wrapped children.
Examples
Basic conditional rendering
With else clause
With else function
With children function
Check if observable is ready
With custom value observable
With wrapper component
Complex conditions
Nested Show components
With complex else content
Loading states with ifReady
Behavior
Conditional tracking
Only the active branch (children or else) is tracked and rendered:Value passing
When children is a function:- Without
$value: Receives the condition value - With
$value: Receives the$valueobservable’s value
ifReady behavior
ifReady uses isObservableValueReady() internally to check if the value is:
- Not
undefined - Not a pending Promise
- Actually has a value
Wrapper usage
Thewrap prop is useful for providing context or layout:
Performance
Show uses useSelector internally with skipCheck: true, which means:
- Re-renders occur when any tracked observable changes
- No deep equality checking on return values
- Efficient for conditional rendering logic
Comparison with JavaScript conditionals
Show component
Equivalent JSX
Advantages of Show:
- More declarative and readable
- Built-in
ifReadyfor async observables wrapprop for providers/context- Children function receives typed value
- Cleaner syntax for complex conditions
Type Parameters
The type of the condition value. Inferred from the
if or ifReady selector.Notes
- Cannot use both
ifandifReadyprops simultaneously elsecan be a function for lazy evaluation- Children function receives
undefinedas value if$valueis not provided and condition is a boolean - Wrapper component must accept a
childrenprop - All props except children are tracked with
useSelector