SolidJSS
SolidJSโ€ข3y agoโ€ข
14 replies
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;
        })
      );


I tried also:
    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
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?