Skip to content

Commit

Permalink
Merge pull request #113 from doghae/kiyeong
Browse files Browse the repository at this point in the history
feat: reviewpage 마무리
  • Loading branch information
gogumalatte authored Aug 6, 2024
2 parents 7b6a747 + 1dcf4a8 commit 71da94b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/pages/Home/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from "@emotion/styled";
import axios from "axios";
import { Box, Text } from "@chakra-ui/react";
import { useAuth } from "@/context/AuthContext";
import { useUser } from "@/context/UserContext";

interface ReviewItem {
questionId: number;
Expand All @@ -13,6 +14,27 @@ interface ReviewItem {
export const ReviewPage = () => {
const { token } = useAuth();
const [reviewData, setReviewData] = useState<ReviewItem[]>([]);
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);
}
};

useEffect(() => {
if (token) {
Expand Down

0 comments on commit 71da94b

Please sign in to comment.