πΉ What is React?
React is a JavaScript library developed by Facebook for building user interfaces (UIs), especially for single-page applications.
πΉ Key Features of React
- Component-Based β Your UI is built using reusable components.
- Declarative β You describe what you want the UI to look like.
- Virtual DOM β React uses a virtual DOM to improve performance.
- JSX β A syntax extension that lets you write HTML inside JavaScript.
πΉ Basic Example
import React from 'react';
import ReactDOM from 'react-dom/client';
function App() {
return <h1>Hello, React!</h1>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
πΉ How to Start?
- Using Create React App (CRA):
npx create-react-app my-app
cd my-app
npm start
- Or use online editors like:
πΉ Core Concepts to Learn Next
- Components (Function vs Class)
- Props & State
- Event Handling
- Conditional Rendering
- Lists and Keys
- useEffect and useState (React Hooks)
The difference between React DOM and the regular DOM (Document Object Model) boils down to how they manage and update the web page.
Real DOM Vs JS DOM
π§± DOM (Regular/Browser DOM)
The DOM is a tree-like structure created by the browser to represent the structure of an HTML document.
- Native to the browser (no libraries involved)
- Manipulated with JavaScript directly using methods like:
document.getElementById("myDiv").innerText = "Hello";
- Updates are immediate and can be expensive if frequent, especially for large UIs.
- Developers must manually handle updates, UI state, and performance optimizations.
βοΈ React DOM (Virtual DOM + React's way of updating the DOM)
React DOM refers to Reactβs abstraction over the browser DOM, using a Virtual DOM behind the scenes.
- Uses a Virtual DOM: a lightweight in-memory copy of the real DOM.
- React renders UI components and builds a virtual DOM tree.
- When something changes (e.g., state or props), React:
- Updates the virtual DOM.
- Diffs it against the previous version (using a process called reconciliation).
- Efficiently updates only the necessary parts of the real DOM.
- Example:
<div>{this.state.text}</div>
π Key Differences
Feature | DOM | React DOM |
---|---|---|
Origin | Native to browser | React library |
Updates | Direct and immediate | Uses diffing & batch updates |
Performance | Slower for large UIs | Faster and optimized |
Abstraction | None | Virtual DOM |
Ease of use | Manual state/logic management | Declarative and component-based |
Single Vs Multi Page Application.
Here's a clear comparison between Single Page Applications (SPA) and Multi Page Applications (MPA) β two different architectural approaches in web development:
π§© 1. What is a Single Page Application (SPA)?
A SPA loads a single HTML page and dynamically updates the content without reloading the whole page.
π§ How it works:
- Loads the core HTML, CSS, and JavaScript once.
- Uses JavaScript (usually a framework like React, Angular, or Vue) to render and update content.
- Navigating between "pages" just updates the DOM via JavaScript (no full page reload).
β Pros:
- Fast after initial load (no page reloads).
- Smooth user experience (like a native app).
- API-driven (easy to decouple frontend/backend).
- Great for mobile and dynamic content.
β Cons:
- Slower initial load (needs to load everything upfront).
- Can have SEO challenges (though this is solvable with SSR/Next.js).
- More complex routing and state management.
π‘ Example:
- Gmail
- Trello
- Twitter (modern version)
π§± 2. What is a Multi Page Application (MPA)?
An MPA consists of multiple separate HTML pages, and every time a user navigates, the browser loads a new page from the server.
π§ How it works:
- Each page is a full HTML document.
- Traditional web apps with server-side rendering.
- Backend handles routing and returns new pages.
β Pros:
- SEO-friendly by default.
- Easier to manage large-scale apps with complex structure.
- Less reliance on JavaScript (can work well even with JS disabled).
β Cons:
- Slower navigation (full page reloads on every request).
- Can feel less seamless (especially compared to SPAs).
- Requires more server resources.
π‘ Example:
- Amazon
- Wikipedia
- Traditional eCommerce sites
- Most server-rendered CMS platforms
π SPA vs MPA Summary
Feature | SPA | MPA |
---|---|---|
Page Reloads | No (JavaScript handles updates) | Yes (each page is a full reload) |
Speed (after load) | Fast (dynamic updates) | Slower (reloads whole pages) |
SEO | Needs extra setup (e.g. SSR) | SEO-friendly by default |
Complexity | More frontend logic | More backend logic |
Initial Load Time | Typically slower | Typically faster |
User Experience | Smoother, app-like | More traditional |
βοΈ Choosing Between Them
Use SPA if:
- You need a highly interactive UI (e.g., dashboards, social media).
- You're building a mobile-like experience.
- SEO is not your top priority, or you're using Server-Side Rendering (SSR).
Use MPA if:
- You need strong SEO support out of the box.
- The app has many unrelated pages (e.g., product listings, blogs).
- You want a simpler structure with server-side rendering.
Top comments (0)