Есть state:
state = {
productsList: [ {
"name":"JACKET",
"price":"10",
"id":"4o"
},
{
"name":"JACKET",
"price":"9.9",
"id":"4"
},
{
"name":"SHOE",
"price":"101",
"id":"65"
},
{
"name":"Enduro",
"price":"15",
"id":"6jy5"
}]
};
Как посчитать сумму значений price в productsList? Пробовал:
countPrice = () => {
let sum = 0;
return this.state.productsList.map((product) => {
console.log(sum);
return sum += product.price;
})
}
Но появляется ошибка в консоли:
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.