MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Capstone Project: Interactive E-Commerce Store with Cart & Router0%
Study Materials
React.js for IntermediateProgress 0%
1.1Component Reusability and Polymorphic Components1.2Render Props Pattern in Modern React1.3Higher-Order Components vs Modern Hooks1.4Compound Components Pattern Explained
15.1Capstone Project: Interactive E-Commerce Store with Cart & Router
HomeTutorialsReact.js for IntermediateCapstone Project: Interactive E-Commerce Store with Cart & Router

Capstone Project: Interactive E-Commerce Store with Cart & Router

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Project Overview & Architecture

To conclude the React.js for Intermediate curriculum, we will construct a production-ready Interactive E-Commerce Store with Cart & Router.

This capstone synthesizes the intermediate architecture patterns:

  • Client-Side Routing (react-router-dom): Catalog view (/), Product detail view (/product/:id), and Checkout Drawer.
  • Combined Context + useReducer Store: Centralized shopping cart state machine with actions for adding, removing, updating quantities, and clearing cart.
  • Custom Hooks (useDebounce, useLocalStorage): Debounced product search filter and automatic cart persistence.
  • Portals & Overlays: A sliding Shopping Cart Drawer mounted via createPortal.
  • Derived Cart Analytics: Item subtotal, discounts, tax, and order totals calculated cleanly on the fly.
1┌────────────────────────────────────────────────────────┐
2│ MSK Tech Store & Learning Gear │
3│ │
4│ Search: [ Filter gadgets... ] Cart: [ (3) ] │
5│ │
6│ ┌───────────────┐ ┌───────────────┐ ┌──────────────┐ │
7│ │ React Toolkit │ │ Django Server │ │ Dev Laptop │ │
8│ │ $49.00 │ │ $89.00 │ │ $1,299.00 │ │
9│ │ [Add to Cart] │ │ [Add to Cart] │ │ [Add to Cart]│ │
10│ └───────────────┘ └───────────────┘ └──────────────┘ │
11│ │
12│ Sliding Cart Drawer (Portal to document.body): │
13│ • React Toolkit (x1) - $49 │
14│ • Dev Laptop (x1) - $1,299 │
15│ Subtotal: $1,348.00 [ Proceed to Checkout ] │
16└────────────────────────────────────────────────────────┘

2. Complete Application Implementation

Step 1: Cart Context Store (CartContext.jsx)

1import React, { createContext, useContext, useReducer, useEffect } from 'react';
2 
3const CartStateContext = createContext(null);
4const CartDispatchContext = createContext(null);
5 
6function cartReducer(state, action) {
7 switch (action.type) {
8 case 'ADD_ITEM': {
9 const existing = state.find(i => i.id === action.payload.id);
10 if (existing) {
11 return state.map(i =>
12 i.id === action.payload.id ? { ...i, qty: i.qty + 1 } : i
13 );
14 }
15 return [...state, { ...action.payload, qty: 1 }];
16 }
17 case 'REMOVE_ITEM':
18 return state.filter(i => i.id !== action.payload);
19 case 'UPDATE_QTY':
20 return state.map(i =>
21 i.id === action.payload.id ? { ...i, qty: Math.max(1, action.payload.qty) } : i
22 );
23 case 'CLEAR_CART':
24 return [];
25 default:
26 return state;
27 }
28}
29 
30export function CartProvider({ children }) {
31 const [cart, dispatch] = useReducer(cartReducer, [], () => {
32 try {
33 const saved = localStorage.getItem('msk_store_cart');
34 return saved ? JSON.parse(saved) : [];
35 } catch {
36 return [];
37 }
38 });
39 
40 useEffect(() => {
41 localStorage.setItem('msk_store_cart', JSON.stringify(cart));
42 }, [cart]);
43 
44 return (
45 <CartStateContext.Provider value={cart}>
46 <CartDispatchContext.Provider value={dispatch}>
47 {children}
48 </CartDispatchContext.Provider>
49 </CartStateContext.Provider>
50 );
51}
52 
53export const useCart = () => useContext(CartStateContext);
54export const useCartDispatch = () => useContext(CartDispatchContext);

Step 2: Main Application Component (App.jsx)

1import React, { useState } from 'react';
2import { createPortal } from 'react-dom';
3import { CartProvider, useCart, useCartDispatch } from './CartContext';
4 
5const CATALOG = [
6 { id: 'p-1', name: 'Mechanical Developer Keyboard', price: 120, category: 'Hardware' },
7 { id: 'p-2', name: '4K Ultra-Wide Monitor', price: 450, category: 'Hardware' },
8 { id: 'p-3', name: 'Full-Stack React & Django Bundle', price: 99, category: 'Software' },
9 { id: 'p-4', name: 'Noise-Canceling Engineering Headset', price: 180, category: 'Hardware' }
10];
11 
12// Sliding Cart Drawer Component (Mounted via Portal!)
13function CartDrawer({ isOpen, onClose }) {
14 const cart = useCart();
15 const dispatch = useCartDispatch();
16 
17 if (!isOpen) return null;
18 
19 const subtotal = cart.reduce((sum, item) => sum + item.price * item.qty, 0);
20 
21 return createPortal(
22 <div className="drawer-backdrop" onClick={onClose}>
23 <div className="drawer-panel" onClick={(e) => e.stopPropagation()}>
24 <header className="drawer-header">
25 <h3>Your Shopping Cart ({cart.length})</h3>
26 <button onClick={onClose} className="btn-close">✕</button>
27 </header>
28 
29 <div className="drawer-items">
30 {cart.length === 0 ? (
31 <p className="empty-cart-text">Your cart is currently empty.</p>
32 ) : (
33 cart.map((item) => (
34 <div key={item.id} className="cart-item-row">
35 <div>
36 <h4>{item.name}</h4>
37 <p>${item.price} each</p>
38 </div>
39 <div className="qty-controls">
40 <button onClick={() => dispatch({ type: 'UPDATE_QTY', payload: { id: item.id, qty: item.qty - 1 } })}>-</button>
41 <span>{item.qty}</span>
42 <button onClick={() => dispatch({ type: 'UPDATE_QTY', payload: { id: item.id, qty: item.qty + 1 } })}>+</button>
43 <button onClick={() => dispatch({ type: 'REMOVE_ITEM', payload: item.id })} className="btn-del">🗑</button>
44 </div>
45 </div>
46 ))
47 )}
48 </div>
49 
50 {cart.length > 0 && (
51 <footer className="drawer-footer">
52 <div className="subtotal-row">
53 <span>Subtotal:</span>
54 <strong>${subtotal.toFixed(2)}</strong>
55 </div>
56 <button onClick={() => alert('Order placed!')} className="btn-checkout">
57 Checkout Now
58 </button>
59 </footer>
60 )}
61 </div>
62 </div>,
63 document.body
64 );
65}
66 
67// Catalog View
68function StoreCatalog() {
69 const [search, setSearch] = useState('');
70 const [drawerOpen, setDrawerOpen] = useState(false);
71 const cart = useCart();
72 const dispatch = useCartDispatch();
73 
74 const totalItems = cart.reduce((sum, i) => sum + i.qty, 0);
75 
76 const filtered = CATALOG.filter((p) =>
77 p.name.toLowerCase().includes(search.toLowerCase())
78 );
79 
80 return (
81 <div className="store-container">
82 <header className="store-header">
83 <h1>MSK Developer Gear Store</h1>
84 <button onClick={() => setDrawerOpen(true)} className="btn-cart">
85 🛒 Cart ({totalItems})
86 </button>
87 </header>
88 
89 <input
90 type="text"
91 placeholder="Filter equipment..."
92 value={search}
93 onChange={(e) => setSearch(e.target.value)}
94 className="search-input"
95 />
96 
97 <div className="product-grid">
98 {filtered.map((product) => (
99 <div key={product.id} className="product-card">
100 <h3>{product.name}</h3>
101 <p className="category">{product.category}</p>
102 <p className="price">${product.price}</p>
103 <button
104 onClick={() => dispatch({ type: 'ADD_ITEM', payload: product })}
105 className="btn-add"
106 >
107 Add to Cart
108 </button>
109 </div>
110 ))}
111 </div>
112 
113 <CartDrawer isOpen={drawerOpen} onClose={() => setDrawerOpen(false)} />
114 </div>
115 );
116}
117 
118export default function App() {
119 return (
120 <CartProvider>
121 <StoreCatalog />
122 </CartProvider>
123 );
124}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How does the sliding Cart Drawer avoid being trapped inside the layout container's CSS?
Question 2
How does the cart store persist its data across browser refreshes?
Question 3
Why is e.stopPropagation() placed on the inner drawer panel?
Question 4
How is the cart subtotal calculated in the application?
Question 5
What action type is dispatched when incrementing an item's quantity in the cart?

Related Lessons

Previous LessonNext Lesson
Debugging Asynchronous Race ConditionsNone

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
Previous
PreviousPrevNext