Skip to content

Instantly share code, notes, and snippets.

@domyen
Last active April 10, 2017 21:56
Show Gist options
  • Save domyen/0ccc37e28b4ee58f7db2c2fd7a2b8e1d to your computer and use it in GitHub Desktop.
Save domyen/0ccc37e28b4ee58f7db2c2fd7a2b8e1d to your computer and use it in GitHub Desktop.
Single-use component example (via @chantastic)
// 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