forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Post.js
34 lines (30 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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import {block, Suspense} from 'react';
import {fetch} from 'react-data/fetch';
import loadComments from './Comments';
function load(params) {
return {
post: JSON.parse(fetch('http://localhost:3001/posts/' + params.id)),
Comments: loadComments(params.id),
};
}
function Post(props, data) {
return (
<>
<h1>Post {data.post.id}</h1>
<h4>{data.post.title}</h4>
<p>{data.post.body}</p>
<hr />
<Suspense fallback={<p>Loading comments...</p>}>
<data.Comments />
</Suspense>
</>
);
}
export default block(Post, load);