I'm taking an online course to learn react. A student posted a solution to a problem that I think is really elegant and I'd like to understand better. The code iterates through an array of items to create a list in the UI.
function ItemsMaker({items}) {
return (
<div className="itemblocks">
{items.map(item => (
<ExpenseItem
title={item.title}
amount={item.amount}
date={item.date} />
))}
</div>
)
}
I think it's really elegant the way the props object is destructured as a parameter to the function. But I'd like to understand better:
why does
{items.map()}
need to be inside curly braces? What principle is being applied here?why does the arrow function inside .map look like
.map(item => (stuff))
vs.map(item => {stuffInsideBraces})