I have a .map()
function that changes isActive
property value of objects in data
array. However wraps it with curly braces returns me undefined whereas wrapping it with parenthesis or no wrap returns the updated value. Curly braces are used as a wrapper in an arrow function but does it work differently for .map()?
const newData = data.map((data) => {
data.label === label ? { ...data, isActive: !data.isActive } : data,
});
console.log(newData)
//undefined
const newData = data.map((data) =>
data.label === label ? { ...data, isActive: !data.isActive } : data,
);
console.log(newData)
//returns updated newData