frontend/src/App.js
// Enable Realtime updates via Socket.io
Enable Realtime updates via Socket.io
Enable Realtime updates via Socket . io
async componentDidMount () {
    this.loadPosts()
    this.io.onMessage('createpost', (post) => {
      this.setState((prevState) => ({ posts: updatePostsForCreateAndEdit(prevState, post) }))
    })
    this.io.onMessage('editpost', (post) => {
      this.setState((prevState) => ({ posts: updatePostsForCreateAndEdit(prevState, post) }))
    })
    this.io.onMessage('deletepost', (post) => {
      this.setState((prevState) => ({ posts: updatePostsForDelete(prevState, post) }))
    })
    this.io.onMessage('likepost', (post) => {
      this.setState((prevState) => ({ posts: updatePostsForLike(prevState, post) }))
    })
  }
async componentDidMount ( ) { this . loadPosts ( ) this . io . onMessage ( 'createpost' , ( post ) => { this . setState ( ( prevState ) => ( { posts : updatePostsForCreateAndEdit ( prevState , post ) } ) ) } ) this . io . onMessage ( 'editpost' , ( post ) => { this . setState ( ( prevState ) => ( { posts : updatePostsForCreateAndEdit ( prevState , post ) } ) ) } ) this . io . onMessage ( 'deletepost' , ( post ) => { this . setState ( ( prevState ) => ( { posts : updatePostsForDelete ( prevState , post ) } ) ) } ) this . io . onMessage ( 'likepost' , ( post ) => { this . setState ( ( prevState ) => ( { posts : updatePostsForLike ( prevState , post ) } ) ) } ) }
Enable Realtime updates via Socket.io
Enable Realtime updates via Socket . io