1
I am trying to modify some properties of an array through an index coming from mine payload.
The code below goes through the array looking for the index and tries to modify its properties. This even works for less complex objects. I made it based on those answers.
This is the structure of my object.
{
"items": [
{
"sellers": [
{
"commertialOffer": {
Price: 0,
ListPrice: 0,
AvailableQuantity: 0
}
}]
}]
}
What should I do to modify the properties of commertialOffer?
I’m coming from the Vue and I’ve suffered a little with React.
I have received some errors with Unexpected token, expected ","
case 'setTotalEstoque':
return {
...state,
arrayFavorito: state.contents.map((content, i) =>
i === action.payload.indice ? {
...content,
items[0].sellers[0].commertialOffer.Price: action.payload.price,
items[0].sellers[0].commertialOffer.ListPrice: action.payload.listPrice,
items[0].sellers[0].commertialOffer.AvailableQuantity: item.AvailableQuantity,
}: content
)
}
I put a second way, improving the organization.
– André Lins