So currently, I have an app that takes posts from the NASA Astronomy photo of the day API and uses that for my picture, date, and description data for posts.
I get the json data from this API (stored in variable yeet) and then I pass it to a map function that puts it in a post format. This is where I do that:
And this is the beginning of the soloPost function that takes the data and puts it in the post format I want:
I got my like button component from an npm library called “react-animated-heart,” and it is added to every post (within the soloPost function):
However, I realized that my current implementation of the like button was flawed, as all buttons were updating the same “isClick” state variable, and thus when one like button is clicked for one post, all of the like buttons get updated. However, I cannot declare a state for each post, as I do not know how many posts the API may render at any given time.
Thus, I need a way to add an autonomous like button to each post on my site that doesn’t trigger another button, preferably using state since I am not sure if the npm library I am using would allow for another way.