Last active
August 29, 2015 14:11
-
-
Save nasum/4c788d89b8e949289264 to your computer and use it in GitHub Desktop.
React.jsのチュートリアルを触る ref: http://qiita.com/tomato360/items/75e485d0aefe12a837a4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CommentBox = React.createClass({ | |
handleCommentSubmit: function(comment) { | |
var comments = this.state.data; | |
var newComments = comments.concat([comment]); | |
this.setState({data: newComments}); | |
}, | |
getInitialState: function() { | |
return {data: []}; | |
}, | |
loadCommentsFromServer: function() { | |
var data = [ | |
{"author": "Pete Hunt", "text": "This is one comment"} | |
]; | |
this.setState({data: data}); | |
}, | |
componentDidMount : function() { | |
this.loadCommentsFromServer(); | |
}, | |
render: function() { | |
return ( | |
<div className="commentBox"> | |
<h1>CommentForm</h1> | |
<CommentList data={this.state.data} /> | |
<CommentForm onCommentSubmit={this.handleCommentSubmit} /> | |
</div> | |
); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CommentList = React.createClass({}); | |
var CommentForm = React.createClass({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.render( | |
<CommentBox />, | |
document.getElementById('content') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment