Guest User

Untitled

a guest
Oct 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. var JSON_URL = "https://api.example.io/comments.json";
  2. class CommentList extends React.Component {
  3. constructor() {
  4. super();
  5. this.state = { comments: [] }
  6. }
  7. componentDidMount() {
  8. $.ajax({
  9. url: JSON_URL,
  10. dataType: 'json',
  11. success: function(data) {
  12. this.setState({comments: data.comments});
  13. }.bind(this)
  14. });
  15. };
  16. render() {
  17. return <ul> {this.state.comments.map((comment) => {
  18. return <li>{comment.body}—{comment.author}</li>;
  19. })} </ul>; }
  20. }
  21. React.render(<CommentList />, document.getElementById('root'));
Add Comment
Please, Sign In to add comment