of arrow function array-callback-return
should we use filter() before map() or just return null for else condition in react jsx?
{airing.genres.map((genre, index) => {
if (index <= 2) {
return (
<span key={genre}>
{genre}
</span>
)
}
return null }
or :
{airing.genres
.filter(( _ , index) => index <= 2)
.map((genre) => {
return (
<span key={genre}>
{genre}
</span>
);
})}
compose
I would go for filter
Why not airing.genres .slice(0, 3) .map(genre => <span key={genre}> {genre} </span> ) ?
yes it's shorter👍 thank you
Always filter before map if possible
Обсуждают сегодня