Tutorials React JS Introduction to React
Ch 1 / 46
Chapter 1 Beginner 6 min read React JS

Introduction to React JS

React is the world's most popular JavaScript library for building user interfaces. Created by Facebook (Meta) and open-sourced in 2013, it has become the go-to choice for single-page applications, dashboards, mobile apps (via React Native), and full-stack frameworks like Next.js. This chapter explains what React is, why it exists, how the Virtual DOM works, and what makes React's component model so powerful — with real code you can run right here.

Advertisement
What you'll learn
What React is — a declarative UI library, not a framework
Why React? — component model, one-way data flow, rich ecosystem
Virtual DOM — how React updates the UI efficiently via diffing
JSX — writing HTML-like syntax inside JavaScript
Components — functions that return UI, the building blocks of every React app
React vs Angular vs Vue — when to choose which
Where React runs — browsers, servers (SSR), mobile (React Native)
Your first React component rendered in the browser

1. What is React?

React (also called React.js or ReactJS) is an open-source JavaScript library for building user interfaces — specifically for the view layer of an application. It was created by Jordan Walke at Facebook and first deployed on Facebook's News Feed in 2011. It was open-sourced in 2013.

React is not a full framework — it doesn't include routing, state management, or HTTP clients by default. Instead, it focuses entirely on rendering UI, giving you the freedom to compose it with whatever other libraries suit your project.

Key Fact As of 2025, React powers websites for Meta, Netflix, Airbnb, Atlassian, Uber, WhatsApp Web, Instagram, and hundreds of thousands of other products globally.
jsx — simplest React component
// A React component is just a JavaScript function that returns JSX function Greeting() { return <h1>Hello, React! 👋</h1>; } // Render it into the DOM ReactDOM.createRoot(document.getElementById('root')) .render(<Greeting />);

The snippet above shows the essence of React: you write a component (a function), and React figures out how to display it in the browser. Everything in React is built from components — buttons, forms, pages, entire apps.

2. Why React? Key Advantages

Developers and companies choose React for a combination of technical benefits and ecosystem maturity. Here are the core reasons:

Component-Based
UIs are split into reusable, self-contained pieces. Build once, use everywhere — from a button to an entire page.
Virtual DOM = Speed
React only re-renders what changed. Diffing the Virtual DOM against the real DOM minimizes expensive browser repaints.
One-Way Data Flow
Data flows top-down from parent to child via props. This makes bugs easier to trace and apps easier to reason about.
Huge Ecosystem
React Router, Redux, Zustand, TanStack Query, Framer Motion, and thousands more libraries integrate seamlessly.
Learn Once, Write Anywhere
Use React skills for web (React), mobile (React Native), desktop (Electron + React), and server (Next.js SSR).
Community & Jobs
Largest UI library community. React consistently tops job posting charts — it's the most-requested front-end skill.
⭐⭐⭐⭐⭐
4.9 / 5 rating
🔥 Most Popular at K2infocom · Vadodara
Frontend Development
Complete Masterclass
Master the full front-end stack — HTML, CSS, JavaScript, React JS, Bootstrap & more. Learn by building 10+ real-world projects. Get certified and job-ready in 3–6 months.
HTML5 & CSS3 JavaScript ES6+ React JS Bootstrap 5 Git & GitHub 5+ Projects Certificate
2,500+ Students Trained
10+ Live Projects
3–6 Months Duration
100% Placement Support
Advertisement

3. The Virtual DOM Explained

The Virtual DOM (VDOM) is one of React's most important concepts. It's a lightweight, in-memory representation of the real browser DOM. When your component's state changes, React doesn't touch the real DOM directly — instead it:

Builds a new Virtual DOM tree from the updated component output
Diffs the new VDOM against the previous snapshot (the "reconciliation" phase)
Applies only the minimal set of changes needed to the real DOM

This process is called reconciliation. The algorithm React uses is called Fiber (introduced in React 16) and it can prioritize updates, pause work, and resume it later — enabling features like Concurrent Mode and Suspense.

Previous VDOM
<div>
<h1> Hello </h1>
<p> Count: 0 </p>

diff
New VDOM (after setState)
<div>
<h1> Hello </h1>
<p> Count: 1 </p>

Only the <p> text changes — React patches just that node in the real DOM.

Pro Tip Always add a key prop when rendering lists. It helps React identify which items changed, were added, or removed — making reconciliation much faster.

4. JSX — JavaScript XML

JSX is a syntax extension for JavaScript that looks like HTML but compiles to React.createElement() calls. You don't have to use JSX, but virtually every React developer does because it makes component structure intuitive and readable.

JSX (what you write)
const element =
  <div className="card">
    <h2>React Rocks!</h2>
    <p>Simple & fast</p>
  </div>;
Compiled JS (what Babel produces)
const element =
  React.createElement(
    'div', {className: 'card'},
    React.createElement('h2',null,'React Rocks!'),
    React.createElement('p', null, 'Simple & fast')
  );

JSX rules you must remember:

className not class Use className for CSS classes in JSX — class is a reserved JS keyword.
One root element JSX must return a single parent element. Wrap siblings in a <div> or a React Fragment: <>...</>
Self-close empty tags <img /> and <br /> must be self-closing in JSX (unlike HTML5).
{} for JS expressions Embed any JavaScript expression inside curly braces: <p>{2 + 2}</p> renders "4". Variables, ternaries, function calls — all work.
camelCase attributes onclickonClick, tabindextabIndex. All event handlers and most attributes are camelCase.
jsx — JSX expressions and rules
function UserCard({ name, age, isAdmin }) { return ( <> {/* Fragment — no extra DOM node */} <div className="card"> <h2>{name}</h2> {/* variable */} <p>Age: {age}</p> {/* expression */} {isAdmin && <span>Admin ✅</span>} {/* conditional */} <img src="/avatar.png" alt={name} /> {/* self-closing */} </div> </> ); }

5. Components — The Building Blocks

Every piece of a React UI is a component. Components can be as small as a button or as large as an entire page. They accept inputs called props and return JSX describing what the UI should look like.

Convention Component names must start with a capital letter (e.g. MyButton). Lowercase names are treated as native HTML elements by React.
jsx — composing components
// Small reusable button component function Button({ label, onClick, variant = 'primary' }) { return ( <button className={`btn btn-${variant}`} onClick={onClick} > {label} </button> ); } // Parent component composes children function App() { return ( <div> <Button label="Save" onClick={() => alert('Saved!')} /> <Button label="Cancel" onClick={() => alert('Cancelled!')} variant="outline" /> </div> ); }
Advertisement

6. React vs Angular vs Vue

All three are popular choices for building SPAs. Here's a concise comparison:

Feature ⚛ React 🅰 Angular 💚 Vue
Type Library (View only) Full Framework Progressive Framework
Language JavaScript / JSX TypeScript JavaScript / SFC
Learning Curve Moderate Steep Gentle
Data Binding One-way Two-way Both
Performance Very High (VDOM) High Very High
Job Demand (2025) 🔥 Highest High (Enterprise) Growing
Mobile React Native Ionic NativeScript
SSR / Meta-framework Next.js, Remix Angular Universal Nuxt.js
When to choose React Choose React when you need flexibility, a massive ecosystem, strong job market alignment, and the option to expand to React Native for mobile later. It's the safest default for most new projects.

7. The React Ecosystem

React's power multiplies through its ecosystem. Here are the key libraries you'll encounter throughout this tutorial series:

React Router
Client-side routing for multi-page React apps. Version 6 is the current standard.
Redux Toolkit
Global state management for complex apps. RTK makes Redux approachable and boilerplate-free.
TanStack Query
Async state management — fetching, caching, synchronizing server data with zero boilerplate.
Next.js
React meta-framework with SSR, SSG, file-based routing, and the new App Router for full-stack apps.
Tailwind CSS
Utility-first CSS — pairs perfectly with React components for fast, responsive UI without writing custom CSS.
Framer Motion
Production-ready animation library for React. Declarative API — animations that feel alive with minimal code.
Free Download
React JS Complete Cheat Sheet — 2026 Edition
Hooks, JSX rules, lifecycle, Redux patterns, Next.js App Router — all on one page.
Download PDF

8. Your First React App (CDN, no build tool)

You don't need Node.js or a build tool to try React. Use the CDN links below to run React directly in any HTML file — perfect for learning and quick demos:

html — React via CDN, no build step
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>My First React App</title> <!-- React + ReactDOM CDN --> <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> <!-- Babel to compile JSX in the browser --> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> </head> <body> <div id="root"></div> <script type="text/babel"> function Counter() { const [count, setCount] = React.useState(0); return ( <div style={{ textAlign: 'center', padding: '40px' }}> <h1>⚛ My First React App</h1> <p>Count: <strong>{count}</strong></p> <button onClick={() => setCount(count + 1)}>Increment +</button> <button onClick={() => setCount(0)} style={{ marginLeft: '8px' }}>Reset</button> </div> ); } ReactDOM.createRoot(document.getElementById('root')).render(<Counter />); </script> </body> </html>
Note The CDN + Babel approach is for learning only. For production, always use a proper build tool like Vite (npm create vite@latest) or Create React App (npx create-react-app my-app).
Advertisement

9. Code It Live — React Playground

The best way to learn React is to write it. Copy any code example from this chapter and paste it into OneCompiler's React IDE — it supports JSX, Babel, hooks, and multiple files with zero setup required. Just click the button below and start experimenting.

Ready to write your first React component?
OneCompiler gives you a full React + JSX + Babel environment in your browser. No Node.js, no install — just open, paste, and run.
Let's Code Now  →
React + JSX Babel compiled Hooks support Opens in new tab Free & no login needed
🚀 Advanced Track · K2infocom
MERN Stack Full-Course — MongoDB · Express · React · Node
Build real-world apps end-to-end. REST APIs, authentication, deployment. Perfect after completing this React series.
MongoDB Express React Node.js
Quick Check — Test Your Understanding
Q1. What is the Virtual DOM and why does React use it?
✅ Answer
The Virtual DOM (VDOM) is a lightweight, in-memory copy of the real browser DOM. React uses it to avoid expensive direct DOM manipulation. When state changes, React:
  1. Builds a new VDOM tree
  2. Diffs it against the previous snapshot (reconciliation)
  3. Only patches the minimal set of changes into the real DOM
This makes React UIs significantly faster than naively re-rendering the entire page on every update.
Q2. What are the key differences between JSX and HTML?
✅ Answer
Key JSX differences from HTML:
  • Use className instead of class
  • Self-close all empty tags: <img />, <br />
  • Events use camelCase: onClick, onChange
  • JSX must return a single root element (or a Fragment <></>)
  • JavaScript expressions go inside curly braces: {count}, {isAdmin && "Admin"}
Q3. Why is React called a "library" and not a "framework"?
✅ Answer
React is a library because it only handles the View layer — rendering UI components. It does not include built-in solutions for routing, form handling, HTTP requests, or global state management. You choose your own libraries for those concerns.

A framework (like Angular) provides an opinionated, all-in-one solution with those features built in, and you build inside its structure. React gives you freedom to compose your own stack.
Multiple Choice Questions
MCQ 1
Which attribute replaces class in JSX?
MCQ 2
What does React's reconciliation process do?
MCQ 3
Which is the correct way to write a valid React component name?
Chapter 1 Summary
  • React is an open-source JavaScript library for building UI — not a framework.
  • It uses a Virtual DOM with diffing/reconciliation to update only what changed.
  • JSX lets you write HTML-like syntax in JavaScript, compiled by Babel.
  • Everything in React is a component — a function that returns JSX.
  • Data flows one-way (parent → child via props) for predictable UIs.
  • React's ecosystem (Router, Redux, Next.js, etc.) makes it the most versatile UI option.
  • Use Vite for production setup; CDN + Babel for quick experiments.

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel