import { useEffect, useState } from 'react'; interface Article { title: string; content: string; url: string; thumbnail: string; } const NewsArticleWidget = () => { const [article, setArticle] = useState
(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); useEffect(() => { fetch('/api/discover?mode=preview') .then((res) => res.json()) .then((data) => { const articles = (data.blogs || []).filter((a: Article) => a.thumbnail); setArticle(articles[Math.floor(Math.random() * articles.length)]); setLoading(false); }) .catch(() => { setError(true); setLoading(false); }); }, []); return (
{loading ? ( <>
) : error ? (
Could not load news.
) : article ? ( {article.title}
{article.title}

{article.content}

) : null}
); }; export default NewsArticleWidget;