map an array in react code example
Example 1: map function in react
function NameList() {
const names = ['Bruce', 'Clark', 'Diana']
return (
<div>
{names.map(name => <h2>{name}</h2>)}
</div>
)
}
Example 2: react loop through array
this.items = this.state.cart.map((item, key) => <li key={item.id}>{item.name}</li>);