Map() implementation
Tue Jul 05 2022 09:43:23 GMT+0000 (Coordinated Universal Time)
Saved by
@jen_magpantay
#javascript
#react.js
// with return with a single child
{events.map((item) => {
return <p>{item.title}</p>;
}
)}
// with return with a multiple children
{events.map((item) => {
return (
<>
<p>{item.title}</p>
<p>{item.description}</p>
</>
);
}
)}
// with return and conditional
{events.map((item, index) => {
if (index % 2 === 0) {
return (
<p>{index}{item.title}</p>
);
}
})}
//no return declaration and single child
{events.map((item, index) => (
<p>{item.title}</p>
)
)}
//no return declaration and multiple chidlren
{events.map((item, index) => (
<>
<p>{item.title}</p>
<p>{item.description}</p>
</>
)
)}
//Ps.: conditionals are only allowed with return declaration
content_copyCOPY
Comments