score:0

class LikeButton extends React.Component {
state = {
    likes: 0
  };

render() {
    
      return '<button>Likes: {this.state.likes} </button>'
  }
}

addLike = () => {
    let newCount = this.state.likes + 1;
      this.setState({
      likes: newCount
    });
  };

score:0

constructor(props) {
     this.state = {
           chatMessages: []
     }
}

async componentDidMount() {
    const chatMessages = (await chatMessages.get()).data();
    this.setState({ chatMessages });
}

addLike(doc) {
      doc.update({likeCount: doc.likeCount + 1});
}

render() {
     return (
         this.state.chatMessages.map((chatMessage) => {
              return (
                 <ChatMessage 
                      chatMessage={chatMessage} 
                      addLike={this.addLike}
                 />
              )
          }
      )
}

Related Query

More Query from same tag