Skip to main content

What is React?

React is a JavaScript library for building user interfaces, created by Facebook (now Meta). Think of it as a way to build interactive websites using reusable pieces called “components.”Key Concepts:
  • Components: Building blocks of your UI (like LEGO pieces)
  • State: Data that can change over time (like a counter value)
  • Props: Data passed from parent to child components (like function arguments)
  • JSX: HTML-like syntax inside JavaScript
Why React?
  • Build once, reuse everywhere (components)
  • Automatically updates UI when data changes
  • Huge ecosystem and community
  • Used by Facebook, Instagram, Netflix, Airbnb, and thousands more
The Mental Model:
Instead of manually manipulating the DOM, you describe what the UI should look like, and React handles the updates.

Essential React Concepts

1. Components

2. State Management

3. Effects & Side Effects

4. Props & Prop Drilling

5. Context API (Avoid Prop Drilling)

100 Essential React Terms

  1. Component - Reusable UI building block
  2. JSX - JavaScript XML syntax
  3. Props - Data passed to components
  4. State - Component’s internal data
  5. Virtual DOM - In-memory representation of UI
  6. Reconciliation - Process of updating the DOM
  7. Rendering - Converting components to UI
  8. Re-rendering - Updating UI when data changes
  9. Mount - Component added to DOM
  10. Unmount - Component removed from DOM
  11. Lifecycle - Stages of component existence
  12. Key - Unique identifier for list items
  13. Ref - Reference to DOM element
  14. Fragment - Group elements without wrapper
  15. Children - Components/elements inside component
  16. Composition - Building complex UIs from simple components
  17. Pure Component - Component with no side effects
  18. Controlled Component - Form input controlled by React state
  19. Uncontrolled Component - Form input managed by DOM
  20. Synthetic Event - React’s cross-browser event wrapper
  1. useState - State management hook
  2. useEffect - Side effects hook
  3. useContext - Context consumption hook
  4. useReducer - Complex state management
  5. useCallback - Memoize functions
  6. useMemo - Memoize computed values
  7. useRef - Persist values across renders
  8. useLayoutEffect - Synchronous useEffect
  9. useImperativeHandle - Customize ref exposure
  10. useDebugValue - Debug custom hooks
  11. useTransition - Non-blocking updates (React 18)
  12. useDeferredValue - Defer expensive updates
  13. useId - Generate unique IDs
  14. useSyncExternalStore - Subscribe to external stores
  15. useInsertionEffect - CSS-in-JS libraries
  16. Custom Hook - Reusable stateful logic
  17. Hook Rules - Rules of Hooks (top-level only, etc.)
  18. Dependency Array - useEffect/useCallback dependencies
  19. Stale Closure - Outdated values in closures
  20. Hook Flow - Order of hook execution
  1. Higher-Order Component (HOC) - Function that wraps components
  2. Render Props - Share code using props
  3. Compound Components - Components that work together
  4. Controlled Props - Props that control state
  5. State Reducer Pattern - Inversion of control for state
  6. Provider Pattern - Context provider pattern
  7. Container/Presentational - Logic/UI separation
  8. Lifting State Up - Move state to common ancestor
  9. Prop Drilling - Passing props through many levels
  10. Code Splitting - Load code on demand
  11. Lazy Loading - Defer component loading
  12. Suspense - Handle async operations
  13. Error Boundary - Catch React errors
  14. Portal - Render outside parent DOM
  15. Forwarding Refs - Pass refs to child components
  16. Memoization - Cache expensive computations
  17. Batching - Group state updates
  18. Concurrent Rendering - Interruptible rendering
  19. Automatic Batching - Batch updates everywhere (React 18)
  20. Transitions - Mark updates as non-urgent
  1. React.memo - Prevent unnecessary re-renders
  2. shouldComponentUpdate - Lifecycle optimization (legacy)
  3. PureComponent - Shallow prop comparison (legacy)
  4. Profiler - Measure render performance
  5. Windowing - Render only visible items
  6. Debouncing - Delay function execution
  7. Throttling - Limit function calls
  8. Virtualization - Render large lists efficiently
  9. Web Workers - Offload heavy computations
  10. Bundle Size - JavaScript file size
  11. Tree Shaking - Remove unused code
  12. Code Splitting - Split into chunks
  13. Prefetching - Load resources early
  14. Hydration - Attach React to SSR HTML
  15. Streaming SSR - Progressive rendering
  1. Local State - Component-specific state
  2. Global State - Application-wide state
  3. Server State - Data from API
  4. URL State - State in URL params
  5. Redux - Predictable state container
  6. Zustand - Lightweight state management
  7. Jotai - Atomic state management
  8. Recoil - Facebook’s state library
  9. MobX - Observable state
  10. XState - State machines
  1. Server Component - Runs on server (Next.js)
  2. Client Component - Runs in browser
  3. Server Actions - Server-side functions
  4. App Router - File-based routing (Next.js 13+)
  5. Pages Router - Legacy routing (Next.js)
  6. Layout - Shared UI across routes
  7. Loading.tsx - Loading states
  8. Error.tsx - Error handling
  9. Route Handlers - API routes
  10. Middleware - Request interception
  11. Static Generation (SSG) - Pre-render at build
  12. Server-Side Rendering (SSR) - Pre-render per request
  13. Incremental Static Regeneration (ISR) - Update static pages
  14. Dynamic Routes - [param] based routes
  15. Parallel Routes - Multiple pages at once

Common Libraries & Tools

Data Fetching

  • TanStack Query (React Query) - Server state management
  • SWR - Stale-while-revalidate
  • Axios - HTTP client
  • GraphQL - Query language
  • tRPC - Type-safe APIs

State Management

  • Zustand - Lightweight, our go-to
  • Redux Toolkit - Redux simplified
  • Jotai - Atomic state
  • Context API - Built-in React

Forms

  • React Hook Form - Performant forms
  • Zod - Schema validation
  • Yup - Validation library
  • Formik - Form management (legacy)

UI Components

  • shadcn/ui - Copy-paste components
  • Radix UI - Headless components
  • Headless UI - Tailwind components
  • Chakra UI - Component library

Styling

  • Tailwind CSS - Utility-first CSS
  • CSS Modules - Scoped styles
  • Styled Components - CSS-in-JS
  • Emotion - CSS-in-JS

Animation

  • Framer Motion - Animation library
  • React Spring - Spring physics
  • GSAP - Professional animations

Routing

  • React Router - Client-side routing
  • TanStack Router - Type-safe routing
  • Next.js Router - Built-in (Next.js)

Testing

  • Vitest - Unit testing
  • Jest - Testing framework
  • React Testing Library - Component testing
  • Playwright - E2E testing

File Structure & Project Organization

Next.js + React Structure

Vite + React Structure

Understanding File-Based Routing (Next.js)

1

Basic Routes

Files create routes automatically:
2

Dynamic Routes

Use square brackets for parameters:
3

Route Groups

Use parentheses to organize without affecting URLs:
4

Special Files

Debugging React Applications

1. React DevTools

2. Common Debugging Patterns

3. Performance Debugging

Testing Commands

Next.js + React

Vite + React

Common Issues & Solutions

Problem: Old React versions required importing ReactSolution:
Problem: Setting state during render causes infinite loopSolution:
Problem: Missing or wrong dependenciesSolution:
Problem: Arrow functions vs regular functionsSolution:
Problem: Missing unique key for list itemsSolution:
Problem: Function captures old valuesSolution:

Best Practices Checklist

1

Component Design

  • Use functional components with hooks
  • Keep components small and focused
  • Separate logic from presentation
  • Use TypeScript for type safety
  • Extract reusable logic into custom hooks
2

State Management

  • Start with local state (useState)
  • Lift state up when needed
  • Use Context for app-wide state
  • Use Zustand/Redux for complex global state
  • Keep state as close to where it’s used as possible
3

Performance

  • Use React.memo for expensive components
  • Memoize callbacks with useCallback
  • Memoize computed values with useMemo
  • Code split with React.lazy
  • Virtualize long lists
4

Error Handling

  • Wrap components in Error Boundaries
  • Handle async errors in useEffect
  • Validate props with TypeScript
  • Show user-friendly error messages
5

Testing

  • Write tests for critical paths
  • Test user behavior, not implementation
  • Use React Testing Library
  • Mock API calls
  • Test accessibility
Common Pitfalls:
  • Don’t mutate state directly (use setState)
  • Don’t call hooks conditionally
  • Don’t forget cleanup in useEffect
  • Don’t use index as key for dynamic lists
  • Don’t optimize prematurely

Quick Reference: Hooks Cheat Sheet

Master these concepts in order:
  1. Components & JSX
  2. Props & State
  3. useEffect & Side Effects
  4. Custom Hooks
  5. Performance Optimization
  6. Advanced Patterns