Created
January 7, 2015 19:59
-
-
Save codyduval/ed29e1fa5eb1ca7d72fb to your computer and use it in GitHub Desktop.
React Components Example
This file contains hidden or 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 PostsList = React.createClass({ | |
| getInitialState: function() { | |
| return { posts: this.props.initialPosts }; | |
| }, | |
| render: function() { | |
| var posts = this.state.posts.map(function(post) { | |
| return <Post key={post.id} post={post} />; | |
| }); | |
| return ( | |
| <div className="posts"> | |
| {posts} | |
| </div> | |
| ); | |
| } | |
| }); | |
| var Post = React.createClass({ | |
| render: function() { | |
| return ( | |
| <div className="post"> | |
| <PostHeader post={this.props.post} /> | |
| <PostContent post={this.props.post} /> | |
| </div> | |
| ); | |
| } | |
| }); | |
| var PostHeader = React.createClass({ | |
| render: function() { | |
| return ( | |
| <div className="post-header"> | |
| <h2>{this.props.post.title}</h2> | |
| <div className="post-meta"> | |
| By {this.props.post.author} – {this.props.post.created_at} | |
| </div> | |
| </div> | |
| ); | |
| } | |
| }); | |
| var PostContent = React.createClass({ | |
| render: function() { | |
| return ( | |
| <div className="post-contents"> | |
| {this.props.post.contents} | |
| </div> | |
| ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment