Switch

Renders the first case whose condition is true, or the default.

Usage

Cases are checked in order and the first true one wins. Pick a status.

tsx
<Switch>
  <Switch.Case when={status === "loading"}>{Spinner}</Switch.Case>
  <Switch.Case when={status === "error"}>{ErrorPanel}</Switch.Case>
  <Switch.Default>{() => <Results rows={rows} />}</Switch.Default>
</Switch>

Direct children only

Switch looks at its direct children. A case inside a fragment or another component is ignored.

tsx
<Switch>
  <>
    <Switch.Case when={isReady}>…</Switch.Case>
  </>
</Switch>

Reference

proptypedefault
children?ReactNode—Switch.Case and Switch.Default, as direct children

Switch.Case

proptypedefault
when?booleanfalserenders this case when true
children?Renderable—what the case renders

Switch.Default

proptypedefault
children?Renderable—rendered when no case matches