React Introduction

What Is React?
React is a declarative JavaScript library for building user interfaces. You compose screens from reusable components, describe markup with JSX, and React updates the DOM when your data changes.
UI = f(state)
Build from components:
function App() { return <h1>Hello</h1>; }
Mount:
ReactDOM.createRoot(root).render(<App />)
React is a library (view layer), not a full framework Created by Jordan Walke at Meta and released as open source (MIT). Pair it with Vite for apps, or try a CDN demo before installing a toolchain.
Why Use React?
Manual DOM updates get hard as UIs grow. React lets you describe the UI for a given state and handles the rest.
| Need | How React helps |
|---|---|
| Reusable UI pieces | Components you compose like Lego blocks |
| Changing data | State updates re-render only what changed |
| Readable markup | JSX keeps structure next to logic |
| Huge ecosystem | Router, forms, Next.js, and countless libraries |
How React Updates the UI
From state change to pixels on screen:
| Step | What happens |
|---|---|
| 1. Render | Components return JSX that describes the UI |
| 2. Virtual DOM | React builds a lightweight tree of elements |
| 3. Diff | On update, React compares the new tree to the old one |
| 4. Commit | Only the needed real DOM nodes change |
Your First React App
Quick CDN demo (no install), or scaffold with Vite for real projects:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello React</title>
</head>
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
function App() {
return <h1>Hello, React!</h1>;
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
</body>
</html> Vite (recommended for projects)
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev How It Works
1. Component. App is a function that returns JSX.
2. Root. createRoot attaches React to the #root DOM node.
3. Render. root.render(<App />) paints the UI on the page.
React vs Vanilla JavaScript
Same browser, different way to build UI:
| React | Vanilla JS |
|---|---|
| Declarative: describe the UI | Imperative: mutate DOM nodes by hand |
| Components + props + state | Custom functions and event listeners |
| JSX templates | HTML strings or createElement |
| Virtual DOM diffs updates | You decide every DOM write |
When to use which
| Use React when… | Prefer vanilla when… |
|---|---|
| The UI has lots of interactive state | The page is mostly static |
| You want reusable component trees | You need zero framework weight |
| The team ships SPAs or dashboards | A few DOM tweaks are enough |
Core Building Blocks
These ideas show up in almost every React app:
| Concept | What it does |
|---|---|
| Component | A function that returns UI (JSX) |
| JSX | HTML-like syntax inside JavaScript |
| Props | Inputs passed from parent to child |
| State | Data that can change and trigger re-renders |
| Hooks | APIs like useState and useEffect |
| Virtual DOM | In-memory tree React diffs before updating the page |
Where Is React Used?
React powers a huge share of modern front ends:
| Use case | Why React fits |
|---|---|
| Single-page apps | Component trees and client-side routing |
| Dashboards | Lots of widgets that update independently |
| Marketing sites | Next.js and similar for SSR / static pages |
| Mobile apps | React Native reuses component ideas |
| Design systems | Shared buttons, forms, and layout primitives |
| Embedded widgets | Mount React into part of an existing page |
Key Takeaways
- React is a UI library—components describe the view.
- JSX + state: describe UI; React updates the DOM.
- Start with a CDN demo, then Vite for real apps.
- Learn JS first—React builds on language fundamentals.
One line: React turns state into UI—practice with Hello, React, then explore Node.js for tooling.
Frequently Asked Questions
Did you know?
React shines when your data changes over time. Build UIs from reusable components, describe markup with JSX, and let React update the DOM efficiently through its virtual DOM.
Try Hello, React!
Open the live editor, then continue with Node.js for a Vite-based workflow.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
14 people found this page helpful
