To handle clicks on the like and unlike buttons, we will set up a like method that will call the appropriate fetch method based on whether it is a like or unlike action, and update the state of like and likes count for the post.
mern-social/client/post/Post.js:
like = () => { let callApi = this.state.like ? unlike : like const jwt = auth.isAuthenticated() callApi({ userId: jwt.user._id }, { t: jwt.token }, this.props.post._id).then((data) => { if (data.error) { console.log(data.error) } else { this.setState({like: !this.state.like, likes: data.likes.length}) } }) }