Open 90sidort opened 3 years ago
Hi @90sidort,
This consecutive post creation issue is happening due to an incomplete implementation. It wasn't covered in the book because it can be completed by extending the example of adding and removing posts. Basically, every time there is an update to a like or comment in a Post, we should also be updating the list of posts passed from the newsfeed.
You could do the following to complete this implementation:
useEffect
only runs when the post
changes:
useEffect(() => {
setValues({...values, like:checkLike(props.post.likes), likes: props.post.likes.length, comments: props.post.comments})
}, [props.post])
Newsfeed
component that gets passed along through PostList
to Post
and is called when a like or comment is added/removed. This function could look as follows:
const updatePost = (newPost, index) => {
const updatedPosts = [...posts]
updatedPosts[index] = newPost
setPosts(updatedPosts)
}
This implementation is applied in the demo that I have hosted: social2.mernbook.com
Let us know if you find more issues or this needs more clarifications.
Hi, I have found an issue that is a bug. Short description:
GIVEN: User is logged AND Home page is opened AND There are older posts visible with comments and likes (e.g 1 like and 1 comment for the latest post) WHEN: User adds new post THEN: New post should not have any likes nor comments
New post is displayed on top of the previous comments and likes
Video available on request.