I saw a lot of docs about stats but I can't find a way to re-render my stats (I'm using redux but I saw this is nothing to do in reducer or action). I only use a function onClick (for likes true or false) and other function to show the results with some conditions:
Here is my functions:
const likesData = useSelector((state) => state.likesReducer);
const handleLikes = async () => {
let id = userData.id;
let idComment = comment.idObject;
dispatch(likesComment(id, idComment)).then(() =>
dispatch(getComment()))
};
const isLiked = () => {
return Array.from(likesData).filter(likes => likes.id === userData.id && likes.idComment === comment.idObject).length > 0;
};
const returnLikes = (commentId) => {
return Array.from(likesData).filter(likes => likes.idComment === commentId).length;
};
Here is my return :
<div className="home-icon-post" onClick={() => handleLikes()} >
{
<FontAwesomeIcon className={`${isLiked(comment.idObject) ? "heartFull"
: "heartEmpty"}`} icon={["fa","heart"]} />
}
</div>
<span>
<p>{returnLikes(comment.idObject)}</p>
</span>
here is my action likes:
And my reducer likes: