Implementing an individual voting counter in each card

Viewed 27

I'm currently working on a React project where I display cards with informations from an array of Objects, so that their content is dynamic. Now I would like to implement a like and a dislike counter on each card to vote the articles.

My problem is, how to fix this, so that when I click on (like), that it just ads 1 to that specific card and not in all of them. Because I'm mapping through the data array.

1 Answers

Look into using the .map method in your JSX. It allows you to iterate through multiple values and you can set your methods to individually mapped elements. Make sure to include a key in the element as well.

Further info: https://reactjs.org/docs/lists-and-keys.html

Related