-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostList.js
More file actions
44 lines (36 loc) · 1.15 KB
/
PostList.js
File metadata and controls
44 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from "react"
import {connect} from "react-redux"
import {fetchPostsAndUsers} from "../actions";
import UserHeader from "./UserHeader";
class PostList extends React.Component{
componentDidMount() {
this.props.fetchPostsAndUsers()
}
renderList() {
return this.props.posts.map(post=>{
return(
<div className="item" key={post.id}>
<i className="large middle aligned icon user"/>
<div className="content">
<div className="description">
<h2>{post.title}</h2>
<p>{post.body}</p>
</div>
<UserHeader userId={post.userId}/>
</div>
</div>
)
})
}
render() {
return(
<div className="ui relaxed divided list">
{this.renderList()}
</div>
)
}
}
const mapStateToProps=(state)=>{
return {posts:state.posts}
}
export default connect(mapStateToProps,{fetchPostsAndUsers})(PostList)