A React application that displays cat facts paired with random user profiles, featuring infinite scroll pagination and real-time data fetching.
- React V.19 - UI Library
- TypeScript - Static type checking
- TanStack Query (React Query) - Data fetching and caching
- TailwindCSS V.4 - Utility-first CSS framework
- React Intersection Observer - Infinite scroll functionality
The application follows a modular architecture with clear separation of concerns:
App.tsx
- Main application componentCard.tsx
- Displays individual cat fact with user informationSkeletonCard.tsx
- Loading placeholder componentError.tsx
- Error state component
useCatFacts
- Manages cat facts data fetching with React QueryuseInfiniteScroll
- Handles infinite scroll functionality
requests.ts
- API integration layer with external services
types.ts
- TypeScript type definitions for API responses and data structures
-
The application fetches data from two external APIs:
- Cat Facts API (
https://catfact.ninja/facts
) - Random User API (
https://randomuser.me/api
)
- Cat Facts API (
-
Data fetching is managed through React Query, providing:
- Automatic caching
- Background updates
- Error handling
- Loading states
-
Infinite scroll implementation:
- Uses Intersection Observer API
- Loads new data when the user reaches the bottom
- Shows loading indicators during data fetching
- Infinite Scroll: Seamless loading of additional content
- Skeleton Loading: Smooth loading states with placeholder content
- Error Handling: Graceful error state management
- Responsive Design: Mobile-friendly layout
- Type Safety: Full TypeScript implementation
- Data Caching: Efficient data management with React Query
// Endpoint: https://catfact.ninja/facts
// Parameters:
// - page: number (pagination)
// - limit: number (items per page)
// Endpoint: https://randomuser.me/api
// Parameters:
// - results: number (number of users)
// - inc: string (included fields)
// - seed: string (consistent results)
- Node.js (v18 or higher)
- npm or yarn
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
src/
├── components/ # React components
├── hooks/ # Custom React hooks
├── services/ # API integration
├── types/ # TypeScript definitions
├── App.tsx # Main component
└── main.tsx # Application entry
- Data Caching: React Query manages data caching to minimize API calls
- Lazy Loading: Content is loaded as needed through infinite scroll
- Optimized Re-renders: Components are structured to minimize unnecessary re-renders
- Type Safety: TypeScript ensures runtime safety and better developer experience
-
React Query over SWR/Custom Hooks
- Built-in caching mechanisms
- Automatic background refetching
- Better TypeScript support
- Simplified infinite query handling
-
Tailwind CSS over CSS-in-JS
- No runtime overhead
- Faster development
- Better performance
- Consistent design system
-
Custom Hook Abstraction
- Separates concerns
- Reusable logic
- Easier testing
- Better maintainability