"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; createdByName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { file_url: string; file_alt: string; }[]; }; export default function PopularNews() { const [popularNews, setPopularNews] = useState([]); const [showData, setShowData] = useState("5"); useEffect(() => { fetchPopularNews(); }, []); async function fetchPopularNews() { try { const res = await getListArticle({ limit: showData, page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }); setPopularNews(res?.data?.data || []); } catch (err) { console.error("Gagal load berita populer:", err); } } return (

BERITA POPULER

{popularNews.slice(0, 3).map((news) => (
{news.title}

{news.title}

))}
{popularNews.slice(3).map((news) => (
{news.title}

{news.title}

))}
{/* Banner */}
Berita Utama
); }