S
SolidJS8mo ago
Fantasy

Removing element from store array doesn't remove rendered items

Hi, i need help with this. I have a store that is shared in a context with some helper functions. I use the below function to add/remove tags (string array).
const mutateTag = (id: string, tagname: string, type: string) => {
setRef(
(meta) => meta.metadata.id === id,
'metadata',
'tags',
produce((tags) => {
if (type === 'add') {
tags?.push(tagname);
}
if (type === 'remove') {
tags = tags?.filter((tag) => tag !== tagname);
}
}),
);
};
const mutateTag = (id: string, tagname: string, type: string) => {
setRef(
(meta) => meta.metadata.id === id,
'metadata',
'tags',
produce((tags) => {
if (type === 'add') {
tags?.push(tagname);
}
if (type === 'remove') {
tags = tags?.filter((tag) => tag !== tagname);
}
}),
);
};
when i add tags to the store, it updates well and new items show up
<Show when={props.metadata.tags}>
<For each={props.metadata.tags}>
{(tag) => (
<ViewBoxTag name={tag} removeTag={removeTag}>
{tag}
</ViewBoxTag>
)}
</For>
</Show>
<Show when={props.metadata.tags}>
<For each={props.metadata.tags}>
{(tag) => (
<ViewBoxTag name={tag} removeTag={removeTag}>
{tag}
</ViewBoxTag>
)}
</For>
</Show>
but when i remove the tags, the items are still visible
2 Replies
thetarnav
thetarnav8mo ago
you’re assigning to the parameter in produce, not actually mutating the store there you can use findIndex + splice instead or do a produce on an an object higher in the state tree
Fantasy
FantasyOP8mo ago
it worked, thanks A solved tag would be cool.
Want results from more Discord servers?
Add your server