You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
761 B

import React from 'react';
import CommentsList from './commentslist.jsx'
import CommentsForm from './commentsform.jsx'
class Comments extends React.Component {
constructor(props){
super(props);
this.state = {
comments: []
}
this.addComment = this.addComment.bind(this);
}
addComment(value){
this.state.comments.push(value); //this alone won't notify React to update the DOM
this.setState({
comments: this.state.comments
});
}
render(){
return <section>
<CommentsList comments={this.state.comments}></CommentsList>
<CommentsForm handleSubmit={this.addComment}></CommentsForm>
</section>
}
}
export default Comments;