I am trying to pass a ES5 style callback to the map function of the array. It doesn't work, but when i change it to an arrow function everything goes well
render(){
return (
<ul>
{this.props.items.map((item, index) => (
<li key={index}>{item}</li>
))
}
</ul>
);
}
return (
<ul>
{this.props.items.map(function(index, item) { (
<li key={index}>{item}</li>
)})
}
</ul>
);
You need to include a return statement, which included by default in ES6
return (
<ul>
{this.props.items.map(function(index, item) { return (
<li key={index}>{item}</li>
);})
}
</ul>
);