Component-Based Architecture & Modern Web Development
INFO 153A/253A - Front-End Web Architecture
UC Berkeley School of Information
October 13, 2025
Part 1: Prep Work Recap
Understanding React's Core Philosophy
From Your Prep: What is React?
"A JavaScript library created and maintained by Facebook for building user interfaces"
React is a UI library, not a framework: It only handles the view layer, unlike Angular which provides everything
Component-based architecture: Think of your UI as LEGO blocks that snap together
Declarative approach: You describe what you want, React figures out how to make it happen
Virtual DOM for performance: React keeps a JavaScript representation of the UI for efficient updates
Created by Facebook in 2013: Built to solve their massive UI complexity problems
Why React Exists
Traditional Approach (Week 7)
Scattered event listeners
Manual DOM updates
Global variables everywhere
HTML, CSS, JS separated
React Approach
Components handle their events
Automatic UI updates
Encapsulated state
Components contain everything
The problem React solves: Managing complex UIs becomes exponentially harder with traditional methods
Facebook's insight: UI = f(state) - the UI should be a pure function of application state
Component isolation: Changes in one component don't break others
Predictable updates: When state changes, React automatically updates the UI
Developer experience: Better debugging, hot reloading, and clear data flow
Prerequisites You've Already Mastered
✅ You're Ready for React!
Weeks 1-7 have prepared you perfectly
JavaScript fundamentals (Week 4 & 6): Variables, arrays, objects, functions - all essential for React
DOM manipulation (Week 7): You understand what React is abstracting away
Array methods (Week 6): map(), filter(), reduce() are React's best friends
Arrow functions (Week 6): The standard way to write functions in React
Modern CSS (Week 3 & 5): Your styling knowledge transfers directly
Event handling (Week 7): React events work similarly but better
The Component Mental Model
Everything is a Component
App
Header
TaskList
TaskItem
TaskItem
Footer
Components are functions: They take inputs (props) and return UI (JSX)
Composability: Small components combine to create complex UIs
Reusability: Write once, use many times with different data
Isolation: Each component manages its own piece of the UI
Think in components: Start seeing every UI as a tree of components
React's Virtual DOM Magic
// What you write (declarative)
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(prevCount => prevCount + 1)}>
Clicked {count} times
</button>
);
}
// What React does for you (imperative)
// 1. Compares virtual DOM trees
// 2. Finds minimal changes needed
// 3. Updates only what changed in real DOM
Virtual DOM is a JavaScript object: Lightweight copy of the real DOM structure
Diffing algorithm: React compares old and new virtual DOM trees
Minimal updates: Only changed elements are updated in the real DOM
Performance win: Batch updates and avoid expensive DOM operations
You never touch the DOM: React handles all DOM manipulation for you
Part 2: JSX - JavaScript in Disguise
Writing HTML that's Actually JavaScript
JSX = JavaScript XML
Syntactic sugar that makes React components readable
JSX is not HTML: It's JavaScript that looks like HTML for developer convenience
Transpilation required: Babel converts JSX to React.createElement() calls
Why use JSX: Writing React.createElement() manually would be a nightmare
It's optional but universal: You could write React without it, but nobody does
Powerful advantage: Full JavaScript power inside your markup
Your First JSX
// What you write (JSX)
function Welcome() {
return (
<div className="container">
<h1>Hello React!</h1>
<p>Welcome to component-based development</p>
</div>
);
}
// What Babel produces (pure JavaScript)
function Welcome() {
return React.createElement('div', { className: 'container' },
React.createElement('h1', null, 'Hello React!'),
React.createElement('p', null, 'Welcome to component-based development')
);
}
JSX makes React human-readable: Imagine writing complex UIs with createElement!
Return statement wrapping: Parentheses help with multi-line JSX
One parent element rule: Every return must have a single root element
Babel does the heavy lifting: Transformation happens automatically in build process
Reusability maximized: TaskItem works for any task data
Part 4: React with Vite
Modern React Development Environment
About Your Prep Work
Prep videos use Create React App - we're using Vite (the industry standard today)
Create React App deprecated: Was official tool, now replaced by Vite
Vite is the modern choice: Faster, lighter, actively maintained
Same React concepts: Everything you learned in prep still applies
Why the switch: Industry moved to Vite in 2023-2024
Both are build tools: Just different ways to run the same React code
Vite benefits: Instant dev server, faster builds, modern tooling
Creating Your First Vite + React App
# Create new Vite project with React template
npm create vite@latest my-portfolio -- --template react
# Navigate to project
cd my-portfolio
# Install dependencies
npm install
# Start development server
npm run dev
# Your app is now running at http://localhost:5173
What Just Happened?
Downloaded Vite React template
Created minimal project structure
Installed React and Vite dependencies
Started instant dev server (no bundling wait!)
Vite scaffolding: Creates project template instantly
Two-step setup: Create, then npm install (installs dependencies)
npm run dev: Vite's dev command (not npm start)
Port 5173 default: Different from CRA's 3000
Instant startup: Dev server ready in milliseconds vs seconds
Hot Module Replacement: Changes reflect instantly
Vite Project Structure
my-portfolio/
├── node_modules/ # Dependencies (never edit)
├── public/ # Static assets (images, fonts)
├── src/ # Your code goes here
│ ├── App.jsx # Root component (note .jsx!)
│ ├── App.css # App styles
│ ├── main.jsx # Entry point (not index.js!)
│ └── index.css # Global styles
├── index.html # Root HTML (in root, not public!)
├── package.json # Dependencies & scripts
├── vite.config.js # Vite configuration
└── .gitignore
index.html in root: Different from CRA (public folder)
main.jsx not index.js: Vite's entry point naming convention
.jsx extension standard: Makes React files explicit (optional but recommended)
src/ is your workspace: All React components and code
public/ for static files: Images, fonts that don't need processing
vite.config.js for setup: Usually don't need to touch this
Understanding main.jsx
// src/main.jsx - The bridge between React and the DOM
import React from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import App from './App.jsx'
// Find the root div in index.html
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
Nearly identical to CRA: Just different filename (main.jsx vs index.js)
This file rarely changes: It's just the connection point
ReactDOM handles browser rendering: React core is platform agnostic
StrictMode helps development: Catches common mistakes and warnings
App component is your starting point: Everything flows from App
Chained syntax: Vite template uses method chaining (same result)
Essential NPM Scripts
// package.json scripts
{
"scripts": {
"dev": "vite", // Development server
"build": "vite build", // Production build
"preview": "vite preview" // Preview production build locally
}
}
Key Difference from CRA
Use npm run dev (not npm start)
npm run dev for development: Your main command (note: not npm start!)
npm run build for production: Creates optimized files in dist/ folder
npm run preview for testing: Test production build locally before deployment
dist/ folder is deployment-ready: Upload to any static host
No eject needed: Vite config is already accessible in vite.config.js
Lightning fast builds: Vite builds are significantly faster than CRA
Part 5: From Assignment 1 to React
Transforming Static HTML to Dynamic Components
Mental Model Shift
From manipulating DOM to declaring components
Assignment 1 was static: HTML and CSS with no interactivity
Assignment 2 adds React: Same design, now interactive and dynamic
Components replace HTML blocks: Each section becomes a component
State replaces hardcoded data: Tasks live in JavaScript, not HTML
Props enable customization: Reusable components with different data