Skip to content

Instantly share code, notes, and snippets.

@sagar-gavhane
Last active October 28, 2018 10:46
Show Gist options
  • Save sagar-gavhane/71982ac369d3d7373a0331166b61dfde to your computer and use it in GitHub Desktop.
Save sagar-gavhane/71982ac369d3d7373a0331166b61dfde to your computer and use it in GitHub Desktop.
This code snippets is created during writing article on react component patterns.
import React, { Component, Fragment } from "react"
class CommentList extends Component {
constructor() {
super()
this.state = { comments: [] }
}
componentDidMount() {
fetch("https://jsonplaceholder.typicode.com/comments")
.then(res => res.json())
.then(comments => this.setState({ comments }))
}
render() {
return (
<Fragment>
<ul>
{this.state.comments.map(({ body, author }) => (
<li>
{body}-{author}
</li>
))}
</ul>
</Fragment>
)
}
}
export default CommentList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment