-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathApp.jsx
38 lines (29 loc) · 854 Bytes
/
App.jsx
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
import './App.scss';
import postsFromServer from './api/posts.json';
import commentsFromServer from './api/comments.json';
import usersFromServer from './api/users.json';
import { PostList } from './components/PostList';
function getUserById(userId) {
const foundedUser = usersFromServer.find(user => userId === user.id);
return foundedUser || null;
}
function getCommentsById(postId) {
const commentsList = commentsFromServer.filter(
comment => comment.postId === postId,
);
return commentsList;
}
const posts = postsFromServer.map(post => {
return {
...post,
user: getUserById(post.userId),
comments: getCommentsById(post.id),
};
});
export const App = () => (
<section className="App">
<h1 className="App__title">Static list of posts</h1>
<PostList posts={posts} />
</section>
);
export default App;