Enterprise Verified
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Architecture 6 min read • Chapter 2 of 26

React Intro

What is React? Learn how React works, why the Virtual DOM makes applications blazing fast, and the history behind React.

React was created by Jordan Walke, a software engineer at Meta, and was first released in 2013. Today, React powers millions of modern web applications worldwide.

How Does React Work?

Instead of directly manipulating the browser's Document Object Model (DOM), React creates a Virtual DOM in memory:

1. State or Props Change in your component
2. React re-renders the component in the Virtual DOM tree
3. React calculates the exact diff between the old and new Virtual DOM
4. React batches and updates ONLY what changed in the real browser DOM

Key Benefits of React

  • Declarative: You describe what the UI should look like for a given state, and React handles updating the DOM.
  • Component-Based: Build encapsulated components that manage their own state, then compose them to make complex UIs.
  • Learn Once, Write Anywhere: Develop web apps with React, and mobile apps with React Native using the exact same design concepts.

Example

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Virtual DOM Demo</title>
    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <style>body{font-family:sans-serif;padding:20px;background:#f8fafc;}.box{background:white;padding:20px;border-radius:12px;border:1px solid #cbd5e1;max-width:400px;}</style>
</head>
<body>
    <div id="root"></div>

    <script type="text/babel">
        function VirtualDomDemo() {
            const [time, setTime] = React.useState(new Date().toLocaleTimeString());

            React.useEffect(() => {
                const timer = setInterval(() => setTime(new Date().toLocaleTimeString()), 1000);
                return () => clearInterval(timer);
            }, []);

            return (
                <div className="box">
                    <h3>Virtual DOM Reconciliation</h3>
                    <p>Only the time string below is re-rendered each second:</p>
                    <div style={{fontSize: "22px", fontWeight: "bold", color: "#04aa6d"}}>{time}</div>
                </div>
            );
        }

        ReactDOM.createRoot(document.getElementById("root")).render(<VirtualDomDemo />);
    </script>
</body>
</html>
Try it Yourself >> Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php

Community Q&A & Discussion

No questions yet. Be the first to start the discussion!
Enterprise Operations Suite

Streamline Employee Payroll & Attendance Operations

Eliminate manual spreadsheet errors. Integrate automated attendance tracking, EPF/ESI statutory calculations, and custom GST invoices.

Copied!

AI Learning Assistant

Ready to explain & guide

Hello! I am your MBS Digital AI Tutor. Ask me to explain concepts, review code, or suggest debugging steps.

Quick Starters:
AI Tutor is thinking...