Comment count update

The updateComments method, which will enable the comments and comment count to be updated when a comment is added or deleted, is defined in the Post component and passed as a prop to the Comments component.

mern-social/client/post/Post.js:

updateComments = (comments) => {    this.setState({comments: comments})}

This method takes the updated list of comments as a parameter and updates the state that holds the list of comments rendered in the view. The initial state of comments in the Post component is set when the Post component mounts, and receives the post data as props.  The comments set here are sent as props to the Comments component, and also used to render the comment count next to the likes action in the action bar ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.