For
Creates a list of elements from a list.
Receives a map function as its child and returns a JSX element for each
list item; if the list is empty, an optional fallback is rendered instead.
The child callback shape follows the keying mode:
- Default /
keyed={true}receives(item, index)whereitemis the raw row value andindexis an accessor. keyed={false}receives(item, index)whereitemis an accessor andindexis a stable number.keyed={(item) => key}receives accessors for both arguments.
Import
import { For } from "solid-js";Type signature
function For<T extends readonly any[], U extends SolidElement>(props: { each: T | undefined | null | false; fallback?: SolidElement; keyed?: true; children: (item: T[number], index: Accessor<number>) => U;}): SolidElement;function For<T extends readonly any[], U extends SolidElement>(props: { each: T | undefined | null | false; fallback?: SolidElement; keyed: false; children: (item: Accessor<T[number]>, index: number) => U;}): SolidElement;function For<T extends readonly any[], U extends SolidElement>(props: { each: T | undefined | null | false; fallback?: SolidElement; keyed: (item: T[number]) => any; children: (item: Accessor<T[number]>, index: Accessor<number>) => U;}): SolidElement;Examples
<For each={items} fallback={<div>No items</div>}> {(item, index) => <div data-index={index()}>{item.label}</div>}</For>