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

seoyeon's avatar
0727    
seoyeon committed
5
6
const userprofile = localStorage.getItem("user");
console.log(userprofile)
우지원's avatar
0726    
우지원 committed
7
const INIT_USER = {
seoyeon's avatar
0727    
seoyeon committed
8
  id: userprofile,
우지원's avatar
0726    
우지원 committed
9
10
11
  name: '',
  img: '',
}
우지원's avatar
0628    
우지원 committed
12

Kim, Chaerin's avatar
Kim, Chaerin committed
13
const HomeProfile = () => {
우지원's avatar
0726    
우지원 committed
14
15
  const [user, setUser] = useState(INIT_USER)

seoyeon's avatar
0727    
seoyeon committed
16
  async function getSetUser(userID) {
우지원's avatar
0726    
우지원 committed
17
18
    try {
      // `/users/${userId}`랑 userId랑 같은지 확인
seoyeon's avatar
0727    
seoyeon committed
19
20
21
22
      console.log('userID',userID)
      const data = await userApi.getUser({id: userID})
      console.log(data)
      setUser(data)
우지원's avatar
0726    
우지원 committed
23
24
25
26
27
28
29
      console.log(user)
    } catch (error) {
      // catchErrors(error, setError)
    }
  }

  useEffect(() => {
seoyeon's avatar
0727    
seoyeon committed
30
31
32
    console.log('예에에에에ㅔ에에')
    getSetUser(userprofile)
  }, [userprofile])
우지원's avatar
0726    
우지원 committed
33

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

export default HomeProfile;