This is a question with a learning purpose, I am stuck in a specific approach. I am playing a little bit with Redux to learn it and I have a question about a part of my code. Let’s say that I have the component that I am attaching as a screenshot which is pretty simple.
This item property is an object of 4 key value pairs (uuid, quantity, price, name ). I am trying to update the quantity in 2 ways. One is successful one is not.
In the reducer this works:
if (action.type === QUANTITY_UPDATED) {
return state.map((item) => {
console.log(item);
if (item.uuid === action.payload.uuid) {
return { ...item, quantity: action.payload.quantity };
}
return item;
});
};
But this does not and return the error I mentioned that .map is not a function. It is probably a stupid mistake I am making but can’t figure it out. Any input?
if (action.type === QUANTITY_UPDATED) {
const item = state.find((item) => item.uuid === action.payload.uuid);
return { ...item, quantity: action.payload.quantity };
}
Moreover, be sure that in Redux reducers, I can’t mutate the properties. Could it be the reason?