comments list updates

master endingreact
Matt Huntington 9 years ago
parent 16db114112
commit b71f5e4388

@ -5,24 +5,22 @@ import CommentsForm from './CommentsForm.js';
class App extends React.Component { class App extends React.Component {
constructor(props){ constructor(props){
super(props); super(props);
this.addComment = this.addComment.bind(this);
this.state = { this.state = {
comments: [ comments: [
{
body:'eat'
},
{
body:'sleep'
},
{
body:'find shelter'
}
] ]
} }
} }
addComment(value){
this.state.comments.push({ body: value });
this.setState({
comments: this.state.comments
});
}
render() { render() {
return <section> return <section>
<CommentsList comments={this.state.comments}/> <CommentsList comments={this.state.comments}/>
<CommentsForm/> <CommentsForm handleSubmit={this.addComment}/>
</section> </section>
} }
} }

@ -1,10 +1,18 @@
import React from 'react'; import React from 'react';
class CommentsForm extends React.Component { class CommentsForm extends React.Component {
constructor(props){
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event){
event.preventDefault();
this.props.handleSubmit(this.refs.body.value);
}
render() { render() {
return <form> return <form onSubmit={this.handleSubmit}>
<input type="text" placeholder="value"/> <textarea ref="body" type="text" placeholder="Your Comment Here"></textarea>
<input type="submit" value="Create Todo"/> <input type="submit" value="Submit Comment"/>
</form> </form>
} }
} }

Loading…
Cancel
Save