NewsLens is a React news reader built with Vite, React Router, and Tailwind CSS. It fetches live headlines from the NewsData.io API and lets users browse top stories, explore categories, run keyword searches, and switch between light and dark mode.
- Browse top headlines on the home page
- Explore category feeds such as business, sports, technology, and world
- Search for news articles with a minimum 3-character query
- View a "For You" feed powered by the selected country
- Toggle dark mode with persistence in
localStorage - See loading skeletons, empty states, and fetch error states
- React 18
- Vite 5
- React Router DOM 7
- Tailwind CSS 4
- NewsData.io API
src/
components/
Navbar.jsx
News.jsx
NewsItem.jsx
SkeletonCard.jsx
context/
contextProvider.jsx
createcontext.jsx
layout/
MainLayout.jsx
pages/
Home.jsx
Category.jsx
Search.jsx
ForYou.jsx
About.jsx
App.jsx
main.jsx
npm installCreate a .env file in the project root:
VITE_NEWS_API_KEY=your_newsdata_api_keynpm run devnpm run buildnpm run preview- Global UI state lives in
NewsContext - Route pages set the active category or search behavior
News.jsxbuilds the API URL fromquery,category, andcountry- Articles are fetched from
https://newsdata.io/api/1/news - Each response item is rendered through
NewsItem.jsx
{
query,
setQuery,
country,
setCountry,
search,
setSearch,
menuOpen,
setMenuOpen,
category,
setCategory,
darkMode,
setDarkMode
}- Search requests are blocked until the query is at least 3 characters long
- Category requests omit the
categoryparameter when the current category isgeneral - Dark mode is stored in
localStorageunder thedarkModekey - The app is currently fully client-side and does not use a database