HomeProfile.js 1.38 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
import { Link } from "react-router-dom";
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
2
3
4
5
6
import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError";

const INIT_USER = {
Kim, Chaerin's avatar
Kim, Chaerin committed
7
8
9
10
  id: localStorage.getItem("user"),
  email: "",
  img: "",
};
우지원's avatar
0628    
우지원 committed
11

Kim, Chaerin's avatar
Kim, Chaerin committed
12
const HomeProfile = () => {
Kim, Chaerin's avatar
Kim, Chaerin committed
13
  const [user, setUser] = useState(INIT_USER);
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
14
15
16

  async function getSetUser(userID) {
    try {
Kim, Chaerin's avatar
Kim, Chaerin committed
17
18
      const data = await userApi.getUser(userID);
      setUser(data);
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
19
20
21
22
23
24
    } catch (error) {
      // catchErrors(error, setError)
    }
  }

  useEffect(() => {
Kim, Chaerin's avatar
Kim, Chaerin committed
25
26
    getSetUser(user.id);
  }, []);
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
27

Kim, Chaerin's avatar
Kim, Chaerin committed
28
  return (
Kim, Chaerin's avatar
merge19    
Kim, Chaerin 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
Kim, Chaerin's avatar
Kim, Chaerin committed
33
            alt="homeProfileImg"
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
34
            src={`/uploads/${user.img}`}
Kim, Chaerin's avatar
Kim, Chaerin committed
35
36
37
38
39
            className="rounded-circle"
            style={{
              width: "157px",
              height: "157px",
            }}
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
40
            // value={user.img}
Kim, Chaerin's avatar
Kim, Chaerin committed
41
42
          />
        </div>
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
43
44
        <h1 className="d-flex justify-content-center"> {user.email} </h1>
        <h2 className="d-flex justify-content-center"> #{user.id} </h2>
Kim, Chaerin's avatar
Kim, Chaerin committed
45
46
47
48
49
50
      </form>
      <div
        style={{ backgroundColor: "#262626", width: "auto", height: "2px" }}
      />
    </Link>
  );
Kim, Chaerin's avatar
Kim, Chaerin committed
51
52
53
};

export default HomeProfile;