Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-eyes-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solid-primitives/keyed": patch
---

docs: add missing keyfn to example
48 changes: 25 additions & 23 deletions packages/keyed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,32 @@ The `keyArray` primitive takes 4 arguments:
- `options` - a fallback for when the input list is empty or missing _(Optional)_

```ts
const mapped = keyArray(source, (model, index) => {
const [name, setName] = createSignal(model().name);
const [description, setDescription] = createSignal(model().description);

createComputed(() => {
setName(model().name);
setDescription(model().description);
const mapped = keyArray(source,
(model) => model.id,
(model, index) => {
const [name, setName] = createSignal(model().name);
const [description, setDescription] = createSignal(model().description);

createComputed(() => {
setName(model().name);
setDescription(model().description);
});

return {
id: model.id,
get name() {
return name();
},
get description() {
return description();
},
get index() {
return index();
},
setName,
setDescription,
};
});

return {
id: model.id,
get name() {
return name();
},
get description() {
return description();
},
get index() {
return index();
},
setName,
setDescription,
};
});
```

Notice that both the value and index arguments are signals. Items are identified only by keys, it means that the items could be copied, replaced, changed, but as long as the key is the same, `keyArray` will treat it as the same item.
Expand Down
Loading