Skip to content

Commit

Permalink
Merge pull request #112 from doghae/kiyeong
Browse files Browse the repository at this point in the history
feat: main.tsx 복구
  • Loading branch information
gogumalatte authored Aug 6, 2024
2 parents b330197 + 5bff0d3 commit 7b6a747
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/MyPage/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import React, { useEffect } from "react";
import styled from "@emotion/styled";
import { Grid, GridItem } from "@chakra-ui/react";
import { StageSelection } from "./StageSelection";
import { UnderSection } from "./UnderSection";
import axios from "axios";
import { useAuth } from "@/context/AuthContext";
import { useUser } from "@/context/UserContext";

export const Main = () => {
const { token } = useAuth();
const { state, dispatch } = useUser(); // UserContext 사용

useEffect(() => {
if (token) {
fetchNickname(token);
}
}, [token]);

const fetchNickname = async (token: string) => {
try {
const response = await axios.get("https://doghae.site/user/nickname", {
headers: {
Authorization: `Bearer ${token}`,
},
});
const nickname = response.data.data; // 닉네임 추출
dispatch({ type: "SET_NICKNAME", payload: nickname }); // 상태 업데이트
} catch (error) {
console.error("데이터 가져오기 실패", error);
}
};

return (
<Wrapper>
Expand Down

0 comments on commit 7b6a747

Please sign in to comment.