stormec56
stormec56

Reputation: 162

How to display text only once per item iterated in React map

I am trying to display text only once per iteration block, but it keeps displaying depending on how many indexed there are iterated.

How can I explain only once?

This is my code:

someArr.map((col, i) => {
  return (
    <div
      key={i}
    >
      {text} // should be displayed only ONCE
      {someRule === someOtherRule && (
        <Icon/>
      )}
   </div>
 )
})

So what happens here is that Icon and all other items get displayed correctly, but {text} gets displayed depending on how many there are iterations. How can I display it only once, regardless of iteration count?

Upvotes: 0

Views: 241

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41397

Check for the first index

  {i === 0 ? text: ''} 

Upvotes: 3

Related Questions