"use client"; import React, { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; import Link from "next/link"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; slug: string; createdByName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { fileUrl: string; file_alt: string; }[]; }; export default function Header() { const [article, setArticle] = useState
(null); const [showData, setShowData] = useState("5"); useEffect(() => { initState(); }, []); async function initState() { const req = { limit: showData, page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; try { const res = await getListArticle(req); setArticle(res?.data?.data?.[0] || null); } catch (error) { console.error("Gagal memuat artikel:", error); } } return (
{article?.title
{article?.categoryName || "Berita Terkini"}

{article?.title || "Memuat..."}

{article ? new Date(article.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", }) : ""}
{article?.createdByName || ""}
0
); }