⚛️ Introduction to React
What is React, Virtual DOM, Vite setup, project structure, and React 18 createRoot.
What is React?
React is a open-source JavaScript library for building interactive user interfaces based on components. Developed by Meta, React emphasizes declarative views, unidirectional data flow, and virtual DOM performance optimizations.
React vs Angular vs Vue Comparison
Comparing major modern web UI frontend frameworks.
| Feature | React | Angular | Vue |
|---|---|---|---|
| Type | UI Library | Full Framework | Progressive Framework |
| DOM Model | Virtual DOM | Real DOM + Change Detection | Virtual DOM |
| Data Binding | One-Way (Unidirectional) | Two-Way & One-Way | Two-Way & One-Way |
| Learning Curve | Moderate | Steep | Gentle |
| Backing Company | Meta (Facebook) | Community Driven |
How the Virtual DOM Works
The Virtual DOM is a lightweight in-memory representation of the real DOM. When state changes occur, React computes the diff between the old and new Virtual DOMs (Reconciliation) and updates only changed nodes in the real DOM.
Setting Up React with Vite
Vite is the recommended modern tool for scaffolding ultra-fast React applications with instant HMR.
npm create vite@latest my-react-app -- --template react cd my-react-app npm install npm run dev
React 18 createRoot API
React 18 uses `createRoot` for mounting applications into the DOM.
import React from 'react'; import { createRoot } from 'react-dom/client'; import App from './App'; const root = createRoot(document.getElementById('root')); root.render( <React.StrictMode> <App /> </React.StrictMode> );