"use client"; import React, { useState, useEffect } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; interface NewsItem { id: string; title: string; summary: string; url: string; imageUrl: string; date: string; } const News = () => { const [news, setNews] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [currentIndex, setCurrentIndex] = useState(0); useEffect(() => { const fetchNews = async () => { try { setLoading(true); // Note: This is a mock implementation - in a real app, you'd need a server-side // component or API that can fetch and parse the content from The Hacker News // as direct web scraping from the client side isn't possible due to CORS restrictions // Simulated response with placeholder data const mockData: NewsItem[] = [ { id: '1', title: 'New Critical Vulnerability Found in Popular Software', summary: 'Security researchers have discovered a zero-day vulnerability affecting millions of users. Patches are being developed urgently.', url: 'https://thehackernews.com/article1', imageUrl: '/api/placeholder/600/300', date: 'March 7, 2025' }, { id: '2', title: 'Major Data Breach Exposes User Credentials', summary: 'A prominent online service reported unauthorized access to their database containing user information. Users are advised to change passwords immediately.', url: 'https://thehackernews.com/article2', imageUrl: '/api/placeholder/600/300', date: 'March 6, 2025' }, { id: '3', title: 'New Ransomware Campaign Targets Healthcare Organizations', summary: 'Cybersecurity experts warn of sophisticated attacks specifically targeting hospitals and medical facilities with encrypted malware.', url: 'https://thehackernews.com/article3', imageUrl: '/api/placeholder/600/300', date: 'March 5, 2025' }, ]; setNews(mockData); } catch (err) { setError('Failed to fetch news. Please try again later.'); console.error('Error fetching news:', err); } finally { setLoading(false); } }; fetchNews(); }, []); const nextSlide = () => { setCurrentIndex((prevIndex) => (prevIndex + 1) % news.length); }; const prevSlide = () => { setCurrentIndex((prevIndex) => (prevIndex - 1 + news.length) % news.length); }; if (loading) { return
Loading latest security news...
; } if (error) { return
{error}
; } if (news.length === 0) { return
No news available at the moment.
; } return (

Latest from The Hacker News

{news[currentIndex].title}

{news[currentIndex].title}

{news[currentIndex].summary}

{news[currentIndex].date} Read More
{news.map((_, index) => (
); }; export default News;