Project Overview
This project demonstrates how to fetch data from an external API when a React component loads. It uses the useEffect Hook to perform asynchronous operations and useState to manage application state.
Users can:
- View posts fetched from a REST API
- Search posts by title
- See a loading spinner while data is being fetched
- Receive an error message if the request fails
- Browse posts displayed in responsive cards
π Features
- Fetch posts from an external REST API
- React Functional Components
- React Hooks (
useState,useEffect) - Search posts by title
- Display the first 10 posts
- Animated loading spinner
- Error handling
- Reusable components
- Responsive layout
- Modern Glassmorphism UI
- Cleanup function using
AbortController
π Technologies Used
- React.js
- JavaScript (ES6+)
- HTML5
- CSS3
- JSX
- React Hooks
- Fetch API
- Async/Await
- Vite
π React Concepts Practiced
- JSX
- Functional Components
- Component Reusability
- Props
- useState Hook
- useEffect Hook
- Fetch API
- Async/Await
- try...catch...finally
- Conditional Rendering
- Array.map()
- Array.filter()
- Cleanup Function
- AbortController
- Responsive UI Design
π How It Works
- The application loads.
useEffectruns once when the component mounts.- Data is fetched from the JSONPlaceholder API.
- A loading spinner is displayed while waiting for the response.
- The JSON response is converted into JavaScript objects.
- Posts are stored in React state.
- The first 10 posts are displayed using reusable
PostCardcomponents. - Users can search posts by title.
- If the API request fails, an error message is displayed.
- If the component unmounts before the request completes, the fetch request is cancelled using
AbortController.
π API Used
JSONPlaceholder
https://jsonplaceholder.typicode.com/posts
π Learning Objectives
This project was built to strengthen understanding of:
- React Hooks
- State Management
- Side Effects with useEffect
- Fetching API Data
- Asynchronous JavaScript
- Error Handling
- Conditional Rendering
- Component-Based Architecture
π Author
Fatima Nasir Awan
Software Engineering Graduate