Skip to content

Commit 9e4dae5

Browse files
committed
Pass data to Post, and render out
1 parent f521bf5 commit 9e4dae5

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/components/App.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import "../styles/app.css";
22
import Post from "./Post";
33

4+
import placeholderData from "../data/posts.json"
5+
46
const App = () => {
57
return (
68
<div className="app">
@@ -13,7 +15,7 @@ const App = () => {
1315
// TODO: Create a Postlist component to wrap all Posts in,
1416
// display name of last upvoted post at the top
1517
}
16-
<Post />
18+
<Post postData={placeholderData[0]} />
1719
</div>
1820
</div>
1921
);

src/components/Post.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import React from "react";
22

3-
const Post = (props) => {
3+
const Post = ({postData}) => {
4+
const {title, author, date, isPublished, body, tags} = postData
5+
46
return (
57
<div className="post">
68
<div className="post-heading">
79
{
8-
// TODO: Use data from props to populate title, author, date
9-
// published, body and tags, validate props
10-
}
11-
<h2>"title"</h2>
12-
{
13-
// TODO: show post body if isPublished, or 'Coming soon!' if not
10+
// TODO: validate props
1411
}
12+
<h2>{title}</h2>
13+
{isPublished ? <p>{body}</p> : <p>Coming soon!</p>}
1514
</div>
16-
<div className="post-author">Author: "author"</div>
17-
<div className="post-date">Published: "date"</div>
15+
<div className="post-author">Author: {author}</div>
16+
<div className="post-date">Published: {date}</div>
1817
<h3>Tags:</h3>
19-
{
20-
// TODO: Create list of all all provided tags
21-
}
18+
<ul>
19+
{tags.map((tag, index) => (
20+
<li key={index}>{tag}</li>
21+
))}
22+
</ul>
2223
</div>
2324
);
2425
};

0 commit comments

Comments
 (0)