Newer
Older
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
40
41
42
43
44
45
import { useNavigate } from 'react-router-dom';
import { UserContext } from '../Context.js';
import Article from '../components/Article.js';
import cookie from 'react-cookies';
import React, { useEffect, useState, useContext } from 'react';
import axios from 'axios';
axios.defaults.withCredentials = true;
function MyPage() {
const userContext = useContext(UserContext);
const [articleList, setArticleList] = useState([]);
const userinfo = cookie.load('name');
let listItem = [];
listItem = articleList.map((article) => {
return (
<Article
key={article._id}
data={article}
></Article>
)
});
useEffect(() => {
requestArticles(userinfo.id)
.then((response) => {
setArticleList(response.data)
})
}, []);
return (
<div className="App">
<h1>{userinfo.name}님의 페이지</h1>
<div className="introduction">
{articleList.length}개의 게시글이 있습니다.
</div>
{listItem}
</div>);
}
async function requestArticles(id) {
const response = await axios({
url: `${process.env.REACT_APP_BACKEND_URL}/article/user/${id}`, // 통신할 웹문서