Skip to content

Commit 259fa44

Browse files
committed
Improve PopularNews component with conditional rendering for empty state and consistent formatting
1 parent eb3fa0d commit 259fa44

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎src/PopularNews.jsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ import React from 'react';
22
import { useGlobalContext } from './Context';
33

44
const PopularNews = () => {
5-
const { isLoading,popularNews } = useGlobalContext();
5+
const { isLoading, popularNews } = useGlobalContext();
66

77
if (isLoading) {
88
return <p>Loading popular news...</p>;
99
}
1010

1111
return (
12-
<div className='popular-news-section'>
12+
<div className="popular-news-section">
1313
<h2>🔥 Trending Tech News</h2>
14-
{popularNews.length > 0 && (
14+
{popularNews.length > 0 ? (
1515
<ul>
1616
{popularNews.map((news) => (
17-
<li key={news.objectID}>
17+
<li key={news.objectID} className="news-item">
1818
<a href={news.url} target="_blank" rel="noopener noreferrer">
1919
{news.title}
2020
</a>
2121
<span className="badge">💬 {news.num_comments || 0} comments</span>
2222
</li>
2323
))}
2424
</ul>
25+
) : (
26+
<p>No popular news available.</p>
2527
)}
2628
</div>
2729
);

0 commit comments

Comments
 (0)