Module 03

React Architecture & Patterns

Moving from "writing React components" to "architecting React applications." We cover the reconciliation process, scalable patterns, and state management strategies.

01.

How React Works Internally

React is not just a UI library; it's a state-synchronization engine. Understanding the Virtual DOM and Reconciliation is key to optimizing performance.

Render Phase

React calls your components, compares the result with the previous render (diffing), and calculates necessary changes. This is pure JS and fast.

Commit Phase

React applies those calculated changes to the actual DOM. This is expensive and where we typically see performance bottlenecks.

02.

Component Design Patterns

Scalable React relies on Composition over Inheritance. We break complex UIs into smaller, focused parts.

Presentational Components

Focus on how things look. They receive data via props and have no dependencies on global stores.

Container Components

Focus on how things work. They fetch data, manage state, and pass it down to presentational components.

Compound Components: Think of the HTML <select> and <option> tags. They work together to share state implicitly. We can replicate this pattern in React Context.

03.

State Management Concepts

Not everything belongs in Redux. Modern architecture splits state into three categories:

  • Server State: Data from an API (Use React Query/SWR).
  • Global Client State: UI themes, user session (Use Context/Zustand).
  • Local State: Form inputs, toggles (Use useState/useReducer).

Lifting State Up: If two components need the same data, move the state to their closest common ancestor.

04.

Scalable Folder Structure

Stop grouping files by type (`/components`, `/hooks`). Start grouping by Feature (`/features/auth`, `/features/cart`). This is known as Colocation.

src/ ├─ features/ // Domain specific logic │ └─ auth/ │ ├─ LoginForm.tsx │ └─ useAuth.ts ├─ components/ // Shared UI (Buttons, Inputs) ├─ hooks/ // Shared logic └─ App.tsx
05.

Reference Material

High-quality resources for this module: