HomeProfile.js 1.34 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
const userprofile = localStorage.getItem("user");
우지원's avatar
0726    
우지원 committed
6
const INIT_USER = {
seoyeon's avatar
0727    
seoyeon committed
7
  id: userprofile,
이재연's avatar
d    
이재연 committed
8
  email: '',
우지원's avatar
0726    
우지원 committed
9
10
  img: '',
}
우지원's avatar
0628    
우지원 committed
11

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

seoyeon's avatar
0727    
seoyeon committed
15
  async function getSetUser(userID) {
우지원's avatar
0726    
우지원 committed
16
    try {
seoyeon's avatar
0727    
seoyeon committed
17
18
      const data = await userApi.getUser({id: userID})
      setUser(data)
우지원's avatar
0726    
우지원 committed
19
20
21
22
23
24
    } catch (error) {
      // catchErrors(error, setError)
    }
  }

  useEffect(() => {
seoyeon's avatar
0727    
seoyeon committed
25
26
    getSetUser(userprofile)
  }, [userprofile])
우지원's avatar
0726    
우지원 committed
27

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

export default HomeProfile;