react smart vs presentation component
React presentation component :-
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
// CommentList.js | |
import React from "react"; | |
const Commentlist = comments => ( | |
<ul> | |
{comments.map(({ body, author }) => | |
<li>{body}-{author}</li> | |
)} | |
</ul> | |
) |
React smart component
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
// CommentListContainer.js | |
import React from "react"; | |
import CommentList from "./CommentList"; | |
class CommentListContainer extends React.Component { | |
constructor() { | |
super(); | |
this.state = { comments: [] } | |
} | |
componentDidMount() {co | |
fetch("/my-comments.json") | |
.then(res => res.json()) | |
.then(comments => this.setState({ comments })) | |
} | |
render() { | |
return <CommentList comments={this.state.comments} />; | |
} | |
} |
Comments