api Request Function 구현 중, 발생한 문제이다.
아래는 gifticon 전체 조회를 하는 함수이다.
export async function getMyGift() {
const response = await fetch(`${ENDPOINT}/gift/mygifts?id=test1234`, {
method: 'GET',
headers: {
Authorization: localStorage.getItem('access_token') as string,
},
credentials: 'include',
});
const result = await response.json();
return result;
}
우리 페이지의 경우 이 함수를 두번 사용하는데. 다음과 같은 구조이다.
//import
export default async function Page() {
const myGiftCard = await getMyGift();
return (
<>
<Header title="내 기프티콘 조회" isFilterButton={false} isPrevButton />
<div className="w-full h-full relative flex justify-center items-center flex-col">
{(() => {
if (myGiftCard.data.data.length === 0) {
return <GiftCardEmptyRegistButton />;
}
if (myGiftCard.data.data.length > 0) {
//여기서 응답 데이터를 넘겨준다.
return <MyGiftCardContainer myGiftCard={myGiftCard} />;
}
return <div>네트워크 에러!</div>;
})()}
</div>
<div className="flex justify-center">
<Navbar />
</div>
</>
);
}
'use client'
export default function MyGiftCardContainer({
myGiftCard,
}: MyGiftContainerProps) {
const { data, isLoading } = useQuery({
queryKey: ['getMyGift'],
queryFn: () => getMyGift(),
initialData: myGiftCard,
});
//... 생략
}