Last active
April 10, 2017 21:56
-
-
Save domyen/0ccc37e28b4ee58f7db2c2fd7a2b8e1d to your computer and use it in GitHub Desktop.
Single-use component example (via @chantastic)
Raw
CommentList.jsx
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
Show hidden characters
// CommentList.jsx (DATA + PRESENTATION) | |
// inspired by Michael Chan https://gist.github.com/chantastic/fc9e3853464dffdb1e3c | |
class CommentList extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { comments: [] } | |
} | |
componentDidMount() { | |
$.ajax({ | |
url: "/my-comments.json", | |
dataType: 'json', | |
success: function(comments) { | |
this.setState({comments: comments}); | |
}.bind(this) | |
}); | |
} | |
render() { | |
return <ul> {this.state.comments.map(renderComment)} </ul>; | |
} | |
renderComment({avatar, author, body}) { | |
return <li>{avatar} {author} {body}</li>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment