'React Upvote & Downvote divs to vote only once
I have a reddit like post where I can Upvote and downvote.
<div className="post-card__vote-container">
<div
onClick={() =>
dispatch(
updateVoteCount({ id: props.id, vote: ActionTypes.UP_VOTE })
)
}
className="post-card__icon"
>
<Icon
icon="akar-icons:arrow-up"
color="gray"
width="50"
height="50"
/>
</div>
<div className="post-card__vote-count">{props.voteCount}</div>
<div
onClick={() =>
dispatch(
updateVoteCount({ id: props.id, vote: ActionTypes.DOWN_VOTE })
)
}
className="post-card__icon"
>
<Icon
icon="akar-icons:arrow-down"
color="gray"
width="50"
height="50"
/>
</div>
</div>
and I send the data to my redux toolkit slice. But I want the user to be able to upvote only once and downvote only once, and ofc you can only do one of the two. any ideas of how to handle it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
