React is an open-source JavaScript library developed by Facebook for building user interfaces, especially single-page applications (SPAs). It helps create reusable UI components, making frontend development faster, cleaner, and more efficient.
| Feature | Library | Framework |
|---|---|---|
| Definition | A collection of tools/functions | A full structure to build an app |
| Control | You control the flow | Framework controls the flow |
| Examples | React, jQuery | Angular, Django, Laravel |
React behaves like a framework when:
If you're building an app using:
React maintains a virtual copy of the real DOM. When a component changes, React compares the old Virtual DOM with the new one (diffing). Only the changed part is updated in the real DOM, making updates fast and efficient.
Hooks are special functions in React that let you use state and lifecycle features in functional components. See full guide
useState() – for state managementuseEffect() – for side effects (like API calls, timers)useContext() – for managing global stateuseRef() – for referencing DOM elements✅ Hooks make functional components as powerful as class components.
npx create-react-app myapp
cd myapp
npm start
Sets up everything automatically. Good for learning and small to medium apps.
npm create vite@latest myapp -- --template react
cd myapp
npm install
npm run dev
| CRA | Vite |
|---|---|
| Slower builds | Lightning-fast HMR |
| Heavy setup | Lightweight and fast |
| Great for beginners | Great for performance-focused devs |
✅ Use Vite for modern projects where performance matters.
npm init react-app myapp (alias of CRA)yarn create react-app myapppnpm create vite (with Vite)Next.js for React apps with SSR (Server-Side Rendering)| Term | Meaning |
|---|---|
| React | JavaScript library for building UIs |
| Virtual DOM | Fast UI updates via virtual representation |
| Hooks | Use state/lifecycle in functional components |
| CRA | Create React App – easy setup |
| Vite | Fast build tool for modern React apps |