I got a page with some blog posts and I want users to have the ability to like/thumbs up each post and see how many likes each post has.
Right now when I like one post, all the posts get the same amount of likes. How do I only like the post I'm clicking?
Here's relevant parts of my code:
const [posts, setPosts] = useState([])
let [thumbsNumber, setThumbsNumber] = useState(0)
const thumbsUp = (x) => {
console.log('Clicked thumb: ', x)
setThumbsNumber((thumbsNumber += 1))
}
return (
<div>
{posts.map((post, index) => (
<div key={index} style={{ marginBottom: '10px' }}>
<p style={{ float: 'right' }}>{thumbsNumber}</p>
<ThumbUpAltIcon
className="thumbsUpBtn"
onClick={() => thumbsUp(post.id)}
></ThumbUpAltIcon>
</div>
))}
</div>