Skip to content

Commit 8c4c8de

Browse files
committed
Create PostList component and add to app
1 parent c15483c commit 8c4c8de

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/components/App.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import "../styles/app.css";
3-
import Post from "./Post";
3+
import PostList from "./Postlist";
44

55
import placeholderData from "../data/posts.json"
66

@@ -11,12 +11,10 @@ const App = () => {
1111
<div className="app__foreground-wrap">
1212
<div className="app__title">Intro to React II</div>
1313
{
14-
// TODO: Send data to Post component and verify it works
15-
// wrap all Posts in a PostList component
1614
// TODO: Create a Postlist component to wrap all Posts in,
1715
// display name of last upvoted post at the top
1816
}
19-
<Post postData={placeholderData[0]} />
17+
<PostList posts={placeholderData} />
2018
</div>
2119
</div>
2220
);

src/components/Postlist.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
4+
import "../styles/postlist.css"
5+
6+
import Post from "./Post";
7+
8+
const PostList = ({ posts }) => {
9+
return (
10+
<div className="postlist">
11+
{posts.map((post) => (
12+
<Post key={post.id} postData={post} />
13+
))}
14+
</div>
15+
);
16+
};
17+
18+
PostList.propTypes = {
19+
posts: PropTypes.arrayOf(
20+
PropTypes.shape({
21+
author: PropTypes.string,
22+
body: PropTypes.string,
23+
date: PropTypes.string,
24+
isPublished: PropTypes.bool,
25+
tags: PropTypes.arrayOf(PropTypes.string),
26+
title: PropTypes.string,
27+
})
28+
).isRequired,
29+
};
30+
31+
export default PostList;

src/styles/postlist.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.postlist {
2+
padding-left: 24px;
3+
padding-right: 24px;
4+
padding-bottom: 24px;
5+
}

0 commit comments

Comments
 (0)