šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

React Introduction: What is React and Why Use It?

Discover what React is, its component-based architecture, and why it has become the standard for building modern interactive user interfaces.

⚔ Total XP: 0|šŸ’» react XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

System Hub

Core logic.

Quick Quiz //

What is the primary danger of ignoring this concept?


šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

React is a declarative, component-based JavaScript library for building user interfaces, created and maintained by Meta. This lesson introduces the core mindset shift — describing what the UI should look like instead of manually manipulating the DOM — that everything else in React builds on.

1Welcome to React

React is a declarative, component-based JavaScript library designed by Meta for building interactive user interfaces. Unlike vanilla JavaScript, where you manually select and mutate DOM elements step by step, React lets you describe what the UI should look like for a given state and handles the actual DOM updates itself.

This shift removes huge amounts of imperative boilerplate — no more manually tracking which elements need to change — making applications significantly easier to reason about, maintain, and scale as they grow.

āœ•
—
+
// React: The Component Engine
localhost:3000

āš›ļø React

SYSTEM READY

2Imperative vs Declarative

In an imperative approach, you write exact step-by-step instructions for mutating the UI — selecting elements, attaching listeners, updating text content by hand — which quickly turns into an unmaintainable web of DOM operations. A declarative approach flips this: you simply declare the final desired UI based on your data.

React's engine then figures out the most efficient way to update the actual DOM to match that declaration, so you stop thinking about the individual steps and start thinking about the end result.

āœ•
—
+
// Vanilla: element.textContent = 'Hello';
// React: return <h1>Hello</h1>;
localhost:3000

Hello Declarative World!

3JSX Syntax

At the core of a React app is the Component — a self-contained JavaScript function that returns a piece of UI. To make writing components intuitive, React uses JSX, a syntax extension that lets you write HTML-like markup directly inside your JavaScript. Behind the scenes, JSX compiles down to plain React.createElement() calls.

Because it's still just JavaScript underneath, JSX merges rendering logic with UI structure, letting you use loops, conditionals, and variables directly within your markup.

āœ•
—
+
function Header() {
  return <header><h1>Code Syllabus</h1></header>;
}
localhost:3000
React

4The Virtual DOM

Direct manipulation of the browser's real DOM is slow and computationally expensive, so React maintains a lightweight, in-memory representation of it called the Virtual DOM. When state changes, React builds a new Virtual DOM tree and compares it against the previous one in a process called reconciliation.

From that comparison, React calculates the minimum number of real DOM mutations needed and applies only those, instead of re-rendering the entire page on every change.

āœ•
—
+
// Virtual DOM: Reconciling changes...
// Update: <span>42</span> -> <span>43</span>
localhost:3000
Virtual DOM
(Fast Memory Tree)
āž”
Real DOM
(Slow Browser Tree)

5Mounting the Application

For React to take control of a webpage, it must be attached, or 'mounted', to a standard HTML element — typically a <div id="root">. Using createRoot from react-dom/client, you tell React exactly where in the page to inject your component tree.

Once mounted with root.render(<App />), React takes over management of the DOM inside that container, and every subsequent update flows through its own rendering process rather than manual DOM edits.

āœ•
—
+
const root = createRoot(document.getElementById('root'));
root.render(<App />);
localhost:3000
div#root
<App /> Mounted!

6Composition

Because components are just JavaScript functions, you can nest them inside one another the same way you nest HTML tags. This is composition: instead of one giant monolithic component, you assemble complex UIs out of small, focused pieces.

A Dashboard component, for example, might contain a Sidebar, a Header, and a DataGrid, each handling its own specific responsibility while the parent simply arranges them together.

āœ•
—
+
<Navbar />
<Main>
  <Card />
</Main>
<Footer />
localhost:3000
Navbar Component
Main Component

7Reusability and Props

Reusability is what lets a React app scale without duplicating code. Instead of hardcoding text or styles inside a component, components accept inputs called 'props' — short for properties — much like function arguments.

Passing different props to the same component, such as <Button label="Save" /> and <Button label="Cancel" />, lets you render the same structural layout with entirely different data, cutting down on maintenance and keeping the app visually consistent.

āœ•
—
+
/* React Composition in Action */
localhost:3000

8React Strict Mode

Wrapping your component tree in <React.StrictMode> renders no visible UI of its own — it's a development-only tool that activates extra checks and warnings for everything inside it. During development, Strict Mode intentionally double-invokes certain functions, like component bodies and some lifecycle logic.

That deliberate double-invocation helps surface impure logic, legacy API usage, and unintended side effects before they ever make it to production, where they'd only run once and might go unnoticed.

āœ•
—
+
/* Next: JSX Architecture */
localhost:3000

āš ļø Strict Mode Active

Double rendering enabled to detect bugs.

9Step-by-Step Breakdown

Welcome to React. Welcome to the world of React, a declarative and component-based JavaScript library designed by Meta for building highly interactive user interfaces. Unlike vanilla JavaScript where you must manually manipulate DOM elements, React allows you to describe exactly what the UI should look like for a given state. This paradigm shift fundamentally eliminates massive amounts of imperative boilerplate, making your codebase significantly easier to maintain and scale.

Imperative vs Declarative. The core philosophy that makes React so powerful is its declarative nature. In an imperative approach, you write exact step-by-step instructions on how to mutate the UI, which quickly becomes an unmaintainable web of DOM selections and event listeners. In a declarative approach, you simply declare the final desired state of the UI based on your data. React's engine then calculates the most efficient way to update the actual DOM to match your declaration.

Components Concept. At the absolute core of React's architecture is the concept of a Component. A component is essentially a self-contained, independent JavaScript function that returns a piece of the user interface. By breaking down complex interfaces into small, reusable components, you can encapsulate logic, styles, and markup together. This makes testing, debugging, and team collaboration exponentially more efficient compared to monolithic HTML files.

JSX Syntax. To make writing components intuitive, React uses JSX (JavaScript XML), a syntax extension that allows you to write HTML-like markup directly inside your JavaScript files. Behind the scenes, JSX is compiled down to standard JavaScript function calls using React.createElement(). This syntax seamlessly merges the rendering logic with UI structure, allowing you to use the full programmatic power of JavaScript directly within your markup.

Understanding the foundational building blocks of React is critical before moving forward. When you write code in React, what is the specific syntax extension that allows you to seamlessly mix HTML-like tags directly inside your JavaScript functions?

  • →JSX
  • →HTML

The Virtual DOM. One of React's most famous performance optimizations is the Virtual DOM. Direct manipulation of the browser's real DOM is incredibly slow and computationally expensive. To solve this, React maintains a lightweight, in-memory representation of the DOM. When the state of your application changes, React generates a new Virtual DOM tree, compares it with the previous one (a process called reconciliation), and calculates the absolute minimum number of real DOM mutations needed.

Mounting the Application. For React to take control of your webpage, it needs to be attached or 'mounted' to a standard HTML element, typically a simple div with the id 'root'. Using the createRoot method from the react-dom/client package, you tell React exactly where to inject your entire component tree. Once mounted, React completely takes over the management of the DOM inside that specific container, ensuring all subsequent updates are lightning fast.

Composition. React's true power unlocks when you embrace composition. Because components are just JavaScript functions, you can nest them inside one another just like standard HTML tags. You can build complex, enterprise-grade applications by assembling small, simple components together. A Dashboard component might contain a Sidebar, a Header, and a DataGrid, each managing its own specific responsibilities and rendering logic.

Reusability and Props. Component reusability is the cornerstone of scaling a React application without duplicating code. Instead of hardcoding text or styles, components can accept inputs called 'props' (short for properties), just like HTML attributes or function arguments. By passing different props to the same component, you can render identical structural layouts with entirely different data, drastically reducing maintenance overhead and ensuring consistency across your app.

Understanding how React optimizes browser performance is a mandatory concept for technical interviews. What is the name of the lightweight, in-memory representation of the DOM that React uses to calculate the absolute minimum number of actual DOM updates required?

  • →Virtual
  • →Shadow

React Strict Mode. When developing React applications, you will often wrap your entire component tree in <React.StrictMode>. This is a special tool that does not render any visible UI. Instead, it activates additional checks and warnings for its descendants. In development mode, Strict Mode intentionally double-invokes certain lifecycle functions and render methods to help you detect impure logic, legacy API usage, and unintended side effects before they reach production.

React Developer Tools. Debugging a React application using the standard browser Elements panel can be frustrating because the compiled DOM doesn't show your Component names or internal state. The React Developer Tools browser extension solves this by providing a dedicated 'Components' tab in your developer tools. It allows you to inspect the React component tree exactly as you wrote it, view real-time prop and state values, and even trace performance bottlenecks.

Live Lab: Component Tree. Observe the interactive nature of React. Even a simple application is composed of multiple nested components working together. In modern development, you will build vast libraries of these reusable UI elements. Think of React as a system of Lego blocks; each block is isolated, but together they form a complex, highly functional architecture.

Mastery Achieved. Introduction mastered! You've learned the difference between declarative and imperative programming, the concept of components, JSX syntax, and how the Virtual DOM optimizes performance. You are now ready to dive deeper into the specific syntax rules of JSX in the next module.

Level Up šŸš€

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1React Doesn't Change the Rules of Accessible HTML

JSX still renders to plain HTML elements, so semantic tags, proper heading order, and ARIA attributes matter exactly as much in a React component as in a static page — React changes how markup is authored, not what markup is accessible.

2Component Boundaries Should Not Break Focus or Landmark Structure

Splitting a page into Header, Nav, and Main components is fine, but each should still render to a single meaningful landmark element so assistive technology sees a coherent document outline rather than a pile of generic divs.

SEO Implications

  • 1

    Client-Rendered React Content May Not Be Visible to Every Crawler

    A plain client-side React app renders its markup after JavaScript executes in the browser, so content that only appears post-hydration can be missed or delayed by crawlers that don't fully execute JavaScript — this is why frameworks like Next.js add server-side rendering on top of React.

  • 2

    Component Reuse Can Accidentally Duplicate Boilerplate Across Pages

    Because React encourages reusing the same component across many routes, it's easy to end up with identical titles, headings, or descriptions on every page unless props are used deliberately to vary that content per route.

Best Practices

Keep Components Small and Focused on One Responsibility

A component that renders a button shouldn't also manage global app state or fetch unrelated data — smaller components are easier to test, reuse, and reason about.

Treat Props as Read-Only Inputs

Never reassign or mutate a prop inside a component. If a component needs to change a value over time, that value belongs in its own state, not in a prop it received from a parent.

Frequent Bugs

THE BUG

Directly editing the DOM alongside React (e.g., with document.querySelector) causes elements to disappear or duplicate unexpectedly.

THE FIX

Let React own the DOM inside its mounted root entirely. Any imperative DOM manipulation should go through refs, not manual selectors, since React's Virtual DOM diffing assumes it has exclusive control of that subtree.

Real-World Examples

A Reusable Button Component Across an App

A single Button component accepts a label and an onClick prop, and gets reused for 'Save', 'Cancel', and 'Delete' actions throughout an application without duplicating markup or styles.

function Button({ label, onClick }) {
  return <button onClick={onClick}>{label}</button>;
}

<Button label="Save" onClick={handleSave} />

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Mutating State Directly

// Wrong const [user, setUser] = useState({ name: 'Alice' }); user.name = 'Bob'; // React won't re-render // Correct setUser({ ...user, name: 'Bob' });

The Solution //

Never mutate a state variable directly (e.g., state.count = 1). Always use the setter function provided by useState to ensure the component re-renders.

The Error //

Missing 'key' prop in lists

// Wrong {items.map(item => <li>{item.name}</li>)} // Correct {items.map(item => <li key={item.id}>{item.name}</li>)}

The Solution //

When rendering a list of elements using .map(), always provide a unique 'key' prop to the outermost element to help React identify which items have changed.

Lesson Glossary

[01]Component

A reusable, independent building block of UI in React.

Code Preview
function MyComponent() {}

[02]Declarative

A programming style where you describe 'what' the UI should look like, rather than 'how' to change it.

Code Preview
UI = f(State)

[03]Virtual DOM

A lightweight copy of the real DOM used to optimize updates.

Code Preview
Reconciliation

[04]JSX

JavaScript XML. A syntax extension that allows you to write HTML-like code inside JavaScript.

Code Preview
return <h1>Hello</h1>;

[05]createRoot

The method used to create a React root for displaying content in a browser DOM element.

Code Preview
ReactDOM.createRoot()

[06]Mounting

The process of a component being rendered into the DOM for the first time.

Code Preview
Component Lifecycle

Continue Learning