-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.js
39 lines (35 loc) · 803 Bytes
/
Post.js
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
import React from "react";
import dataSource from "./dataSource";
import Author from "./Author";
import Comments from "./Comments";
export default function Post({ data }) {
if (data == null) {
return null;
}
const post = data.post;
return (
<main>
<article>
<h1>{post.title}</h1>
<Author author={data._Author} />
<div>{post.body}</div>
</article>
<Comments comments={data._Comments} />
</main>
);
}
Post.fetch = async (id) => {
const commentsGen = Comments.fetch(id);
const [post, comments] = await Promise.all([
dataSource.post(id),
commentsGen.next(),
]);
return {
post,
_Comments: {
prefetch: comments.value,
generator: commentsGen,
},
_Author: await Author.fetch(post.authorId),
};
};