HomeProfile.js 1.38 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
import { Link } from "react-router-dom";
우지원's avatar
0726    
우지원 committed
2
3
4
5
6
7
8
9
import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";

const INIT_USER = {
  id: '',
  name: '',
  img: '',
}
우지원's avatar
0628    
우지원 committed
10

Kim, Chaerin's avatar
Kim, Chaerin committed
11
const HomeProfile = () => {
우지원's avatar
0726    
우지원 committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  const [user, setUser] = useState(INIT_USER)

  const id = localStorage.getItem('user');

  async function getUser(id) {
    try {
      // `/users/${userId}`랑 userId랑 같은지 확인
      const User = await userApi.user(id)
      console.log(User)
      setUser(User.data)
      console.log(user)
    } catch (error) {
      // catchErrors(error, setError)
    }
  }

  useEffect(() => {
    getUser(id)
  }, [id])

Kim, Chaerin's avatar
Kim, Chaerin committed
32
33
34
35
36
  return (
    <Link to={`/profile/${id}`} className="text-decoration-none text-dark">
      <form className="flex-column align-items-center justify-content-center m-2">
        <div className="d-flex justify-content-center">
          <img
우지원's avatar
0726    
우지원 committed
37
            // src="cherry.jpg"
Kim, Chaerin's avatar
Kim, Chaerin committed
38
39
40
41
42
            className="rounded-circle"
            style={{
              width: "157px",
              height: "157px",
            }}
우지원's avatar
0726    
우지원 committed
43
            value={user.img}
Kim, Chaerin's avatar
Kim, Chaerin committed
44
45
          />
        </div>
우지원's avatar
0726    
우지원 committed
46
47
        <h1 className="d-flex justify-content-center"> {user.name} </h1>
        <h2 className="d-flex justify-content-center"> #{user.id} </h2>
Kim, Chaerin's avatar
Kim, Chaerin committed
48
49
50
51
52
53
      </form>
      <div
        style={{ backgroundColor: "#262626", width: "auto", height: "2px" }}
      />
    </Link>
  );
Kim, Chaerin's avatar
Kim, Chaerin committed
54
55
56
};

export default HomeProfile;