S
SolidJS14mo ago
Ladvace

Filtering array in object keyed store inside a produce

In the snippet above I have a keyed object, for each key there is an array, that I filter, the filter doesn't seems working, what is the best way to do it?

setObj(
produce((prev) => {
prev[guy.job] = [
...(prev[guy.job] || []).filter((guys) => guys.id !== guy.id),
guy,
];
return prev;
})
);

setObj(
produce((prev) => {
prev[guy.job] = [
...(prev[guy.job] || []).filter((guys) => guys.id !== guy.id),
guy,
];
return prev;
})
);
I tried also:
setObj(guy.job, (prev) => {
const filteredPrev = (prev || []).filter(
(guys) => guys.id !== guy.id
);
return [...filteredPrev, guy];
});
setObj(guy.job, (prev) => {
const filteredPrev = (prev || []).filter(
(guys) => guys.id !== guy.id
);
return [...filteredPrev, guy];
});
https://playground.solidjs.com/anonymous/eaff2e17-2327-4890-95d8-5c30307672ea
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
9 Replies
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Ladvace
Ladvace14mo ago
I updated the example, here it should be more clear, when you click the button UPDATE DATA I update the array with just some of the old objects, reming martin and mark, despite that and the filtr you can still see them https://playground.solidjs.com/anonymous/7d0d22e7-e1af-4e27-8785-b2da846aeca9
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Ladvace
Ladvace14mo ago
nevermind I fixed it, my bad
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Ladvace
Ladvace14mo ago
that's why it wasn't working XD idk if you updated the url but it still doesn't work as it should
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Ladvace
Ladvace14mo ago
oh yeah this works, I was figuring out if there was a way to do that without doing
setObj("A", []);
setObj("B", []);
setObj("C", []);
setObj("A", []);
setObj("B", []);
setObj("C", []);
since the Jobs can be dynamic
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Ladvace
Ladvace14mo ago
they are static for sake of semplicity but the data object come from some api, they can be more or less, they are dynamic, otherwise I would have created a store for each of the jobs the button is just to explain the problem, in reality data get automatically updated there is no button to update it anyway I fixed resetting the whole object before mapping it
Want results from more Discord servers?
Add your server
More Posts