⚛️

React E-Commerce
Coaching Session

8 April 2026 · From Scratch to Components

React + Vite Tailwind CSS Context API Clean Code

Today's Plan

What we're doing today

📌
Session kick-off
Repo check-in, Slack bookmarks, Q&A culture
🏗️
Build from scratch
Vite + React + Tailwind, live together
🧩
Component thinking
Layout blocks → React components
🌐
Context preview
Why state lives in App.jsx — for now

Before We Code

Working with the repo

Open the Slack channel
All important links are pinned in your bookmarks tab
Clone / pull the latest from GitHub
git pull origin main
Open each milestone README
It explains the code blocks, theoretical considerations, and provides links for self-study
Ask questions — in public
If you're stuck, someone else is too. Post it in the Slack channel
Code examples only work with Tailwind installed
That's why we're setting it up together today, step by step

Live Demo

React + Tailwind from zero

Run these commands in order.

# 1. Create a new Vite React project
npm create vite@latest my-shop -- --template react

# 2. Enter the project folder
cd my-shop

# 3. Install dependencies
npm install

# 4. Install Tailwind CSS v4 for Vite
npm install tailwindcss @tailwindcss/vite

# 5. Add the Tailwind Vite plugin in vite.config.js
#    Then add this to src/index.css:
#    @import "tailwindcss";

# 6. Start the dev server
npm run dev

💡 vite.config.js is still needed for the Tailwind Vite plugin. tailwind.config.js is usually not needed in Tailwind v4.

Design First

Before writing a single line of code —

Sketch or draft an outline of the website.

🎨
Figma
Digital wireframing & component design
✏️
Any drawing tool
Excalidraw, draw.io, iPad notes
📓
Manual / hand-written
Timeless & direct transfer of ideas

Think in [blocks] → map those to React Components. Every box you draw on paper becomes a <Component />.

HTML Structure → React Components

What goes where?

<Greeting /> or <Welcome />
Hero banner, tagline, call-to-action
<Header /> with navbar or menu
Logo, navigation links, cart icon
<Main />
Product grid, filters, and core page content
<Sidebar />
Sidebar filters, related items, or extra info
<Footer />
Links, socials, copyright
Each block = one component file
src/components/Header.jsx
src/components/ProductCard.jsx

Milestone 2 Status

Components for your e-commerce app

🗂️
Header
Logo, nav, cart icon badge
🛍️
ProductCard
Image, name, price, Add to Cart
📦
ProductList / Main
Maps products → renders cards
🛒
CartSidebar
List of added items, totals
🔢
CartBadge
Shows cart count in Header
🔍
FilterBar (future)
Filter by category / price

💡 Personalise: add your own colours, product data, or a WishlistButton. Make it yours!

Good Question!

Why does state still live in App.jsx?

Milestone 2
  • → Cart state lives in App.jsx
  • → Passed down as props
  • → Works, but gets messy at scale
  • → Called prop drilling
Milestone 3
  • → Search and filter state in App.jsx
  • → Also passed down as props
  • → Same pattern, different feature
  • Still no Context yet

💡 The App.jsx code is very similar in M2 and M3 because both milestones apply local state management at the top level and pass data down via props.

Future Milestone — Context

The solution to prop drilling: Context

// src/context/CartContext.jsx  ← new file
import { createContext, useContext, useState } from "react";

const CartContext = createContext();

// Provider wraps the whole app — holds state here
export function CartProvider({ children }) {
  const [cart, setCart] = useState([]);
  const addToCart = (product) =>
    setCart((prev) => [...prev, product]);

  return (
    <CartContext.Provider value={{ cart, addToCart }}>
      {children}
    </CartContext.Provider>
  );
}

// Custom hook — any component can call this
export const useCart = () => useContext(CartContext);

Then in main.jsx: wrap <App /> with <CartProvider>. Now every component can call useCart() directly — no props needed.

🚀

Now — make it yours

You all have the same base project. Now diverge. Add your own touches — that's where learning becomes real.

🎨
Own colour palette
Change Tailwind classes, create your theme
🧩
Extra components
WishlistButton, SearchBar, StarRating…
📦
Own product data
Pick a category you like — books, plants, gear

We'll share work in breakout rooms — show your peers what you built 👀

⚛️

Let's build it together

Ask questions. Break things. Fix them. That's exactly how this works.

Slack → questions in public README → read it first Breakout → show your work