From 8f4a6bcd99f23b2e810511ad5f24ab1b4ca150fa Mon Sep 17 00:00:00 2001 From: choi Date: Tue, 14 Jan 2025 17:31:07 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AC=B4=ED=95=9C=20=EB=A3=A8=ED=94=84=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/home/AlbumSection.tsx | 55 +++------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) diff --git a/src/components/home/AlbumSection.tsx b/src/components/home/AlbumSection.tsx index a3a13f4..5115e1e 100644 --- a/src/components/home/AlbumSection.tsx +++ b/src/components/home/AlbumSection.tsx @@ -4,23 +4,16 @@ import { Album } from "@/types/album"; import { cn } from "@/lib/utils"; import Image from "next/image"; import Link from "next/link"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { formatDate } from "@/lib/format"; -import { Skeleton } from "@/components/ui/skeleton"; -import { Button } from "@/components/ui/button"; -import { RefreshCcw } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; export function AlbumSection() { const [albums, setAlbums] = useState([]); - const [isLoading, setIsLoading] = useState(true); - const [error, setError] = useState(null); const { toast } = useToast(); - const fetchAlbums = async () => { + const fetchAlbums = useCallback(async () => { try { - setError(null); - setIsLoading(true); const response = await fetch( `${process.env.NEXT_PUBLIC_API_BASE_URL}/albums?page=0&pageSize=6`, { @@ -32,55 +25,17 @@ export function AlbumSection() { setAlbums(data); } catch (error) { console.error('Failed to fetch albums:', error); - setError(error instanceof Error ? error.message : "앨범 목록을 불러오는데 실패했습니다."); toast({ variant: "destructive", + title: "앨범 목록을 불러오는데 실패했습니다.", description: error instanceof Error ? error.message : "앨범 목록을 불러오는데 실패했습니다.", }); - } finally { - setIsLoading(false); } - }; + }, [toast]); useEffect(() => { fetchAlbums(); - }); - - if (isLoading) { - return ( -
-

최신 앨범

-
- {[...Array(6)].map((_, i) => ( -
- - - -
- ))} -
-
- ); - } - - if (error) { - return ( -
-

최신 앨범

-
-

{error}

- -
-
- ); - } + }, [fetchAlbums]); return (