Overview
You can render arrays of TemplateResults with .map() inside html. For lists that insert, remove, or reorder, use repeat(items, keyFn, templateFn) so existing DOM nodes move with their keys instead of being recreated.
repeat is re-exported from lit-html via mates. For thousands of rows, step up to virtualList from mates-virtual — see /docs/directives/virtual.
.map() vs repeat() vs virtualList
|
API
|
Best for
|
Notes
|
|---|---|---|
items.map(…)
| Short / append-only | Simple. May recreate nodes on reorder. |
repeat(items, keyFn, tpl)
| Keyed lists | Moves existing nodes — better for mutable lists. |
virtualList(…)
| Huge lists | From mates-virtual — only visible rows in the DOM. |
Rendering lists with repeat()
.map() works for simple lists, but
repeat(items, keyFn, templateFn) is more efficient when
items are added, removed, or reordered — it moves existing DOM nodes
instead of recreating them.