title: How to count for each mapped element?
body: <p>trying to write an onClick for my React project. I have results mapped out. I am trying to keep a count for each of those elements, but with a global variable (index) it breaks if I use more than one clickable element per session. I have tried to do id.index, adding (id) + index etc but am stumped. How do I properly use the unique id's to track the index for each card? Thanks</p>
  <pre><code>function onClick(id) {
      let index = 0;
      index++;
      if (index &gt;= 1) {
        dosomething
      } else if (index === 0) {
        dosomethingelse
      }
    }
  </code></pre>