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

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

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

seoyeon's avatar
0727    
seoyeon committed
17
  async function getSetUser(userID) {
우지원's avatar
0726    
우지원 committed
18
    try {
우지원's avatar
0728    
우지원 committed
19
20
      console.log('userID', userID)
      const data = await userApi.getUser( {userID} )
seoyeon's avatar
0727    
seoyeon committed
21
22
      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
    getSetUser(userprofile)
  }, [userprofile])
우지원's avatar
0726    
우지원 committed
32

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

export default HomeProfile;