mapArray
Reactively maps an array, reusing the previously-mapped value for unchanged items.
The callback shape follows the keying mode:
- Default /
keyed: truereceives(item, index)whereitemis the raw row value andindexis an accessor. keyed: falsereceives(item, index)whereitemis an accessor andindexis a stable number.keyed: item => keyreceives accessors for both arguments.
This is the underlying helper that powers <For>. App code should use
<For> directly; reach for mapArray when implementing custom list
components.
options.keyed—true(default for primitives) compares by identity;falsefalls back to index-only mapping; pass a function(item) => keyfor stable identity by extracted key.options.fallback— accessor returning a value to show when the input is empty.
Import
import { mapArray } from "solid-js";Type signature
function mapArray<Item, MappedItem>( list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: { keyed?: true; fallback?: Accessor<any>; name?: string }): Accessor<MappedItem[]>;function mapArray<Item, MappedItem>( list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options: { keyed: false; fallback?: Accessor<any>; name?: string }): Accessor<MappedItem[]>;function mapArray<Item, MappedItem>( list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options: { keyed: (item: Item) => any; fallback?: Accessor<any>; name?: string; }): Accessor<MappedItem[]>;Examples
const view = mapArray(items, (item, index) => `${index()}: ${item.label}`, { fallback: () => "no items",});Related types
Maybe
type Maybe<T> = T | void | null | undefined | false;