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
| prop | type | default | |
|---|---|---|---|
children? | ReactNode | — | Switch.Case and Switch.Default, as direct children |
Switch.Case
| prop | type | default | |
|---|---|---|---|
when? | boolean | false | renders this case when true |
children? | Renderable | — | what the case renders |
Switch.Default
| prop | type | default | |
|---|---|---|---|
children? | Renderable | — | rendered when no case matches |