<Repeat>
Edit this page<Repeat> renders its children a specified number of times. Unlike <For>, it does not perform list diffing — it simply renders count instances.
import { Repeat } from "solid-js"import type { JSX } from "solid-js"
function Repeat(props: { count: number from?: number children: (index: () => number) => JSX.Element fallback?: JSX.Element}): JSX.ElementBasic usage
<Repeat count={5}> {(index) => <div>Item {index()}</div>}</Repeat>Renders:
Item 0Item 1Item 2Item 3Item 4Dynamic count
The count prop is reactive. When it changes, the component adjusts the number of rendered instances:
const [rows, setRows] = createSignal(3)
<Repeat count={rows()}> {(i) => <tr><td>Row {i()}</td></tr>}</Repeat>
<button onClick={() => setRows((r) => r + 1)}>Add Row</button>When to use
Use <Repeat> when:
- You need to render a fixed number of elements (e.g., star ratings, pagination dots, grid cells)
- The content doesn't come from a data array
- You don't need list diffing or keying
Use <For> when:
- You're rendering items from a data array
- Items have identity and may be reordered, added, or removed
Using from
The from prop sets the starting index (default 0):
<Repeat count={3} from={1}> {(index) => <div>Page {index()}</div>}</Repeat>Renders: Page 1, Page 2, Page 3
Fallback
The fallback prop displays content when count is 0:
<Repeat count={items().length} fallback={<p>No items</p>}> {(index) => <div>Item {index()}</div>}</Repeat>Props
| Name | Type | Default | Description |
|---|---|---|---|
count | number | The number of times to render children. | |
from | number | 0 | The starting index value. |
children | (index: () => number) => JSX.Element | A callback receiving the index accessor. | |
fallback | JSX.Element | Content to display when count is 0. |