This commit is contained in:
Tomas Dvorak
2026-02-24 10:33:59 +01:00
parent 409acd2e08
commit 898a3c303f
1374 changed files with 290409 additions and 29187 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"id": "46035bdfa1867064487f0374",
"source": "solid:signals",
"type": "github-document",
"title": "map-array",
"content": "---\ntitle: mapArray\nuse_cases: \u003e-\n efficient list rendering, dynamic arrays, cached list transformations,\n optimized updates, for loop alternatives\ntags:\n - arrays\n - lists\n - rendering\n - caching\n - optimization\nversion: '1.0'\ndescription: \u003e-\n Efficiently map reactive arrays in SolidJS with cached transformations.\n Reduces unnecessary re-renders by tracking items by reference.\n---\n\n```ts\nimport { mapArray } from \"solid-js\"\n\nfunction mapArray\u003cT, U\u003e(\n\tlist: () =\u003e readonly T[],\n\tmapFn: (v: T, i: () =\u003e number) =\u003e U\n): () =\u003e U[]\n\n```\n\nReactive map helper that caches each item by reference to reduce unnecessary mapping on updates.\nIt only runs the mapping function once per value and then moves or removes it as needed.\nThe index argument is a signal. The map function itself is not tracking.\n\nUnderlying helper for the `\u003cFor\u003e` control flow.\n\n```ts\nconst mapped = mapArray(source, (model) =\u003e {\n\tconst [name, setName] = createSignal(model.name)\n\tconst [description, setDescription] = createSignal(model.description)\n\n\treturn {\n\t\tid: model.id,\n\t\tget name() {\n\t\t\treturn name()\n\t\t},\n\t\tget description() {\n\t\t\treturn description()\n\t\t},\n\t\tsetName,\n\t\tsetDescription,\n\t}\n})\n```\n\n## Arguments\n\n| Name | Type | Description |\n| :---- | :----------------------------- | :----------------------- |\n| list | `() =\u003e readonly T[]` | The source array to map. |\n| mapFn | `(v: T, i: () =\u003e number) =\u003e U` | The mapping function. |",
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/reference/reactive-utilities/map-array.mdx",
"metadata": {
"path": "src/routes/reference/reactive-utilities/map-array.mdx",
"repo": "solidjs/solid-docs",
"repo_url": "https://github.com/solidjs/solid-docs.git",
"size": 1478,
"source_type": "github"
},
"hash": "2bf425086836f7405ba3a7680a1e240f8a08e58de6b2db1e72b302f2fb1f2aab",
"timestamp": "2026-02-23T11:43:00.189972121+01:00"
}