Skip to content

Luan-Neumann-Dev/udemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Udemy Clone

A fully functional e-commerce course platform clone built with React β€” featuring category browsing, detailed course pages, and a persistent shopping cart powered by Context API + useReducer.

React Styled Components React Router Vite

Udemy.mp4

πŸš€ View Live Demo

🎯 About

Udemy Clone is a React SPA that replicates the core UI and shopping experience of the Udemy platform. Users can browse courses by category, view detailed course pages with ratings, syllabi and instructor info, add items to a cart, and proceed to checkout β€” all with a persistent cart that survives page refreshes via localStorage.

The project was built to practice advanced React patterns, specifically global state management with Context API and useReducer, client-side routing with dynamic parameters, and component styling with Styled Components.

✨ Key Features

  • 🏠 Home Page β€” Hero slider, featured course list, and category grid
  • πŸ“‚ Category Filtering β€” Dynamic route per category rendering filtered course cards
  • πŸ“– Single Course Page β€” Full course detail view: description, star rating, syllabus, what you'll learn, pricing and add-to-cart
  • πŸ›’ Shopping Cart β€” Add, remove and clear items, with total price calculation
  • πŸ’Ύ Persistent Cart β€” Cart state is saved to localStorage and restored on page load
  • πŸ“± Responsive Layout β€” CSS Grid breakpoints from 1 to 4 columns adapting to screen size
  • 🎠 Hero Carousel β€” Auto-play image slider built with react-slick

πŸ› οΈ Tech Stack

Frontend:

  • React 18 β€” Component architecture, hooks (useState, useEffect, useReducer, useContext)
  • React Router DOM v6 β€” Multi-page routing with dynamic segments (/courses/:id, /category/:category)
  • Styled Components v6 β€” Component-scoped CSS-in-JS styling with theming variables
  • React Slick β€” Hero banner carousel
  • React Icons β€” Icon library used across UI elements

State Management:

  • Context API β€” Three isolated contexts: CartContext, CoursesContext, SidebarContext
  • useReducer β€” Predictable state transitions for cart operations and course data

Build Tool:

  • Vite β€” Fast dev server and optimized production build

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/Luan-Neumann-Dev/udemy.git
 
# Navigate to project
cd udemy
 
# Install dependencies
npm install
 
# Start the dev server
npm run dev

Then open http://localhost:5173 in your browser.

Or visit the live demo β†’

πŸ“ Project Structure

udemy/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/         # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ Navbar.jsx      # Top bar with cart badge and sidebar toggle
β”‚   β”‚   β”œβ”€β”€ Sidebar.jsx     # Mobile navigation drawer
β”‚   β”‚   β”œβ”€β”€ Hero.jsx        # Homepage banner carousel
β”‚   β”‚   β”œβ”€β”€ Course.jsx      # Course card (used in lists)
β”‚   β”‚   β”œβ”€β”€ CourseList.jsx  # Featured courses section
β”‚   β”‚   β”œβ”€β”€ CategoriesList.jsx
β”‚   β”‚   β”œβ”€β”€ CartItem.jsx    # Single item row in cart
β”‚   β”‚   β”œβ”€β”€ StarRating.jsx  # Visual star rating component
β”‚   β”‚   β”œβ”€β”€ Tabs.jsx
β”‚   β”‚   β”œβ”€β”€ Loader.jsx
β”‚   β”‚   └── Footer.jsx
β”‚   β”œβ”€β”€ pages/              # Route-level page components
β”‚   β”‚   β”œβ”€β”€ HomePage.jsx
β”‚   β”‚   β”œβ”€β”€ CoursesPage.jsx     # Filtered by category
β”‚   β”‚   β”œβ”€β”€ SingleCoursePage.jsx
β”‚   β”‚   └── CartPage.jsx
β”‚   β”œβ”€β”€ context/            # Global state providers
β”‚   β”‚   β”œβ”€β”€ cartContext.jsx
β”‚   β”‚   β”œβ”€β”€ coursesContext.jsx
β”‚   β”‚   └── sidebarContext.jsx
β”‚   β”œβ”€β”€ reducers/           # Pure reducer functions
β”‚   β”‚   β”œβ”€β”€ cartReducer.js
β”‚   β”‚   β”œβ”€β”€ coursesReducer.js
β”‚   β”‚   └── sidebarReducer.js
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ data.js         # Static course dataset
β”‚   β”‚   β”œβ”€β”€ images.js       # Centralized image imports
β”‚   β”‚   └── constants.js
β”‚   └── actions.js          # Action type constants

πŸ’‘ Technical Highlights

Context API + useReducer for Global State

Instead of prop drilling, all shared state is managed through three independent contexts. Each follows the same pattern: a context, a provider with useReducer, and a custom hook for consumption.

// Dispatching a cart action
const addToCart = (courseID, image, course_name, creator, discounted_price, category) => {
    dispatch({ type: ADD_TO_CART, payload: {
        courseID, image, course_name, creator, discounted_price, category
    }})
}

localStorage Cart Persistence

The cart initializes from localStorage and syncs on every state change via useEffect, so items survive full page reloads without any backend.

const loadCartFromStorage = () => {
    let cart = localStorage.getItem('cart');
    return cart ? JSON.parse(cart) : [];
}
 
useEffect(() => {
    dispatch({ type: GET_CART_TOTAL })
    localStorage.setItem('cart', JSON.stringify(state.cart))
}, [state.cart])

Duplicate Prevention in Cart Reducer

Before adding an item, the reducer checks for an existing entry by ID β€” preventing duplicates without needing extra UI logic.

if (action.type === ADD_TO_CART) {
    const exists = state.cart.filter(item => item.courseID === action.payload.courseID);
    if (exists.length < 1) {
        return { ...state, cart: [...state.cart, action.payload] }
    }
    return { ...state }
}

πŸ“š What I Learned

Technical Skills:

  • Structuring multiple useReducer + Context patterns in a scalable, non-overlapping way
  • Managing derived state (total items, total amount) reactively inside a reducer
  • Using Styled Components for component-scoped styling with CSS variables and media queries
  • Navigating dynamic routes with useParams to fetch and display contextual data

Best Practices:

  • Centralizing all action type strings in a single actions.js file to avoid typos
  • Separating data-fetching/state logic (context + reducers) from presentational components
  • Handling empty states gracefully (empty cart page with redirect CTA)

πŸ—ΊοΈ Roadmap

  • Search bar with real-time course filtering
  • Wishlist feature
  • Checkout flow with order summary
  • Course ratings filterable on category page
  • Migrate static data to a mock REST API (e.g. JSON Server)

πŸ“ Notes

  • All course data is static β€” stored locally in src/utils/data.js
  • Not affiliated with Udemy, Inc. This is a frontend practice project

πŸ“„ License

MIT License - see LICENSE for details.

πŸ‘€ Author

Luan Neumann


⭐ Found this helpful? Give it a star!

About

A React e-commerce clone of the Udemy platform with category browsing, detailed course pages, and a persistent shopping cart using Context API + useReducer.

Topics

Resources

Stars

Watchers

Forks

Contributors