Last active
October 28, 2018 10:46
-
-
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.
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
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