title: React add JSX to variables in map every loop
body: <p>Hi i have an array which i want to map only once and i wonder if i can do something like this:</p>
  
  <pre><code>  let markersResult;
    let polylines;
  
    markers.map((marker, index: number) =&gt; {
      const nextMarker = markers[index + 1];
  
      markersResult += (
        &lt;UserMapMarker key={String(index)} marker={marker} /&gt;
      )
  
      if (nextMarker &amp;&amp; marker.alertsStatus === nextMarker.alertsStatus ) {
        polylines += (
          &lt;p&gt;polyline&lt;/p&gt;
        )
      }
    })
  
    return (
      &lt;&gt;
        {markersResult}
        &lt;div&gt;
          {polylines}
        &lt;/div&gt;
      &lt;/&gt;
    )
  </code></pre>
  
  <p>It is important to me to use solution similar to that because i have to check if marker has the same value as next marker in loop and then do something with polylines </p>