Conversation
yangashley
left a comment
There was a problem hiding this comment.
Nice work practicing React! Let me know if you have any questions about the comments.
🟢 for react-chatlog
Side note - I encourage you to pratice making more frequent commits after small code changes. I see that your commit history has 1 commit, but making a bunch of small commits allows you to go revisit your code at specific points in your development which will help with debugging in the future.
| // console.log(chatMessages); | ||
|
|
||
| // const [likedMap, setLikedMap] = useState({}) |
| addLike: PropTypes.func, | ||
| removeLike: PropTypes.func, |
| liked: PropTypes.bool, | ||
| addLike: PropTypes.func, | ||
| removeLike: PropTypes.func, |
| const addLike = () => setLikedCount(likedCount + 1); | ||
| const removeLike = () => setLikedCount(likedCount - 1); |
There was a problem hiding this comment.
Can you think of how you could combine the logic from addLike() and removeLike() into one method like updateLike()? The bodies of these 2 methods look very similar, the difference being + or - so maybe we can add some logic by passing in a boolean value
updateLike = isLiked => { // your logic in here }There was a problem hiding this comment.
Another comment about updating likedCount state with setLikedCount. When state represents something like a counter, we need to depend on a state's previous value and increment the previous value.
setLikedCount(prevState => prevState + 1)
This video here does a great job explaining why
No description provided.