After going through various stack overflow questions and guidance, I have reached this point. Essentially, my code is supposed to return a new array by updating a single id. However, even though the updatedProducts array is being generated correctly when I console.log it, my store state is not being updated. Here is how my state object looks:
allProducts:[
{
"product_name": '',
"code": '',
"id": ''
}
],
Below is the mutation I am using:
UPDATE_PRODUCT : ({allProducts},payload) =>{
let updatedProducts = allProducts.map(product => {
if(product.id === payload.id){
return Object.assign({}, product, payload);
}
return product;
})
allProducts = updatedProducts;
}
Although I can see the correct result when logging updatedProducts, the allProducts array remains unchanged. Any ideas why?