'use client'; import { Search } from 'lucide-react'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { toast } from 'sonner'; interface Discover { title: string; content: string; url: string; thumbnail: string; } const Page = () => { const [discover, setDiscover] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/discover`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }); const data = await res.json(); if (!res.ok) { throw new Error(data.message); } data.blogs = data.blogs.filter((blog: Discover) => blog.thumbnail); setDiscover(data.blogs); } catch (err: any) { console.error('Error fetching data:', err.message); toast.error('Error fetching data'); } finally { setLoading(false); } }; fetchData(); }, []); return loading ? (
) : ( <>

Discover


{discover && discover?.map((item, i) => ( {item.title}
{item.title.slice(0, 100)}...

{item.content.slice(0, 100)}...

))}
); }; export default Page;