Now siizeVariant
is a string Array and I want to add Strings to it with an onClick event. findIndex
works fine. It's just the concat section. I guess it's wrong to use it there but I have no idea what to do else :/
const [selectedP, setSelectedP] = useState([
{
name: "Uomo - Valentino",
productId: "H114",
sizeVariants: []
},
{
name: "Uomo - Valentino",
productId: "H243",
sizeVariants: []
}
])
setSelectedP((prev as any[]) => {
const index = selectedP.findIndex((sP: any) => sP.productId === productId);
return [
...prev.slice(0, index),
{
...prev[index],
sizeVariants: prev.sizeVariants.concat(string),
},
...prev.slice(index + 1),
];
})
}
This is the error I get:
prev.sizeVariant is undefined