Switch, Match & Index in SolidJS

From the SolidJS cheat sheet ยท Control Flow ยท verified Jul 2026

Switch, Match & Index

Multi-condition rendering with Switch/Match and primitive-keyed iteration with Index.

tsx
// Quick Reference
import { Switch, Match, Index } from "solid-js";

<Switch fallback={<p>Not found</p>}>
  <Match when={route() === "home"}><Home /></Match>
  <Match when={route() === "about"}><About /></Match>
</Switch>
๐Ÿ’ก Switch renders the first matching Match โ€” use fallback for the default case
โšก Index is keyed by position โ€” use it for primitive arrays (strings, numbers)
๐Ÿ“Œ In Index, the item is a signal but the index is a plain number โ€” opposite of For
๐ŸŸข For vs Index: For recycles DOM nodes by reference, Index recycles by position
switchmatchindexcontrol-flow

More SolidJS tasks

Back to the full SolidJS cheat sheet