I have an object like this:
const fruits = {
"Orange": { "price": 0.25, "inventory": 10},
"Banana": { "price": 0.30, "inventory": 10},
"Apple": { "price": 0.95, "inventory": 10},
}
and I want to write reducer to get object like this:
const fruits = {
"Orange": { name: "Orange", "price": 0.25, "inventory": 10},
"Banana": { name: "Banana", "price": 0.30, "inventory": 10},
"Apple": { name: "Apple", "price": 0.95, "inventory": 10},
}
My reducer:
const fruitsByName = (state = {}, action) => {
switch (action.type) {
case "RECEIVE_FRUITS":
return action.products
default:
return state
}
}
Please help me out, I feel like I've tried everything.