For

Renders one item for each entry in a list, and a fallback when the list is empty.

One
Two
Three

Usage

Code
import { For } from '@leverui/components';
Code
<For each={[]} fallback={...} />

Examples

Object

Here's an example of using the For component to loop over an object.

Wren

Powers: Lightweaving, Pathfinding

Corin

Powers: Stormcalling, Farsight

Mira

Powers: Healing, Stonecraft

Fallback

Use the fallback prop to render a fallback component when the array is empty.

No items to show

Guides

Adds no wrapper element and no styles. Items that stay in the list stay mounted. The index is an accessor: call it to read the item's position in the original array.

each={undefined} renders nothing. Empty slots in a sparse array are skipped, and the other items keep their original index. For is not announced as a list, so use ul, ol, and li when it is one.

Props

PropDefaultTypeDescription
each—T[] | readonly T[] | undefinedArray to loop over.
fallback—JSX.Element | undefinedShown when the array is empty.
children—(item: T, index: Accessor<number>) => JSX.ElementRenders one item. Gets the item and index accessor.