class FeedPost extends Component {
constructor(props) {
super(props);
this.state = {
showComments: false
}
}
handler = () => {
this.setState({
showComments: !this.state.showComments
})
};
render = () => {
const {post} = this.props;
return <li>
<div>{post.title}</div>
<div
onClick={this.handler}
style={{
cursor: "pointer",
color: "blue",
textDecoration: "underline",
userSelect: "none"
}}
>
{this.state.showComments ? "Hide comments" : "Show comments"}
</div>
{this.state.showComments && (
<ul>
{post.comments.map((comment, i) => (
<li key={i}>{comment.text}</li>
))}
</ul>
)}
<Link to={`/post/${post.id}`}>Open</Link>
</li>
}
}
Остальные компоненты не нужно трогать.