๐ง Introduction to React & โ๏ธ JSX (JavaScript XML)

Table of contents
- ๐ง Introduction to React (with Real-Life Examples) : React Topic 1
- โ What is React?
- ๐ค Why use React?
- ๐ What is SPA (Single Page Application)?
- โ๏ธ Setting Up the Environment
- ๐ Create First React App
- ๐ฆ Whatโs Inside the React App Folder?
- โ Summary
- โ๏ธ JSX (JavaScript XML) โ React Topic 2

๐ง Introduction to React (with Real-Life Examples) : React Topic 1
โ What is React?
React is a JavaScript library used to build user interfaces (UI) โ especially for single-page applications (SPA).
Think of React as a smart helper that makes your website fast, dynamic, and interactive without reloading the page again and again.
๐ Real-Life Example:
Imagine you are using Zomato. You click on a restaurant, it opens the menu โ but the entire page doesnโt reload. Thatโs React in action! It loads only the part of the page that needs to change.
๐ค Why use React?
๐ Difference from JavaScript / jQuery:
Feature | JavaScript / jQuery | React |
Page Reload | Full page reload on actions | No reload โ fast updates |
Code Structure | Unstructured, messy for big apps | Component-based & organized |
Reusability | Difficult | Easy using components |
Performance | Slower in large apps | Fast with Virtual DOM |
Data Flow | Complicated | One-way data flow = easy to track |
React is perfect when you're building large web apps โ like eCommerce, dashboards, social media sites, etc.
๐ What is SPA (Single Page Application)?
SPA means your whole website runs in a single HTML page.
Only the content inside changes as you click around โ not the whole page.
๐งโ๐ป Real-Life Example:
When you use Gmail, you click on Inbox, Sent, Drafts โ but the URL changes slightly and the page updates without reloading.
React makes this magic happen using React Router (weโll learn that later).
โ๏ธ Setting Up the Environment
To start working with React, you need to set up a few tools.
1. Install Node.js
Go to https://nodejs.org
Download & install the LTS version
2. Install VS Code (Code Editor)
Download and install it
Add the "ES7+ React/Redux Snippets" extension (for fast coding)
๐ Create First React App
We use a tool called Create React App (CRA) to quickly set up a basic React project.
๐ Steps:
Open terminal or command prompt
Type this:
npx create-react-app my-first-app
It will take a few minutes to set up
Go to the folder:
cd my-first-app
- Start the development server:
npm start
๐ What Happens Next?
Your browser will open at
http://localhost:3000
Youโll see a spinning React logo โ your first React app is ready!
๐ฆ Whatโs Inside the React App Folder?
public/
: Contains the HTML filesrc/
: Where your React code lives (JSX, components, etc.)App.js
: Main component shown firstindex.js
: Entry point of the application
โ Summary
React is a powerful JS library for building modern web apps
Itโs faster and more scalable than traditional JS or jQuery
It allows building SPAs โ smooth, fast, and user-friendly websites
Setup is easy using
create-react-app
Would you like to:
Continue to Topic 2: JSX next in the same format. go ahead โฌ๏ธโฌ๏ธ.
Awesome! Let's continue with React Topic 2: JSX (JavaScript XML).
โ๏ธ JSX (JavaScript XML) โ React Topic 2
โ What is JSX?
JSX stands for JavaScript XML.
JSX is a syntax extension that allows us to write HTML-like code inside JavaScript โ used mainly in React.
JSX makes writing UI components easier and cleaner. Instead of using React.createElement
, we can write code that looks like HTML.
๐ Real-Life Example:
You write:
//jsx//
<h1>Hello, world!</h1>
//ye aapko jsx file me likhna he , jsx he and niche jo example he vo norMAL HTML HE//
Instead of:
//js//
React.createElement("h1", null, "Hello, world!")
Much cleaner and readable, right? Thatโs why we use JSX.
๐ง Why use JSX in React?
Easier to write UI components
Looks like HTML โ easy for beginners to learn
Helps catch errors during compilation
More readable and manageable for large codebases
โ๏ธ JSX Syntax Rules
JSX looks like HTML, but it has some important differences:
1. Return one parent element
In JSX, your component must return only one parent element.
โ Correct:
//jsx//
return (
<div>
<h1>Hello</h1>
<p>Welcome!</p>
</div>
);
โ Wrong:
//jsx//
return (
<h1>Hello</h1>
<p>Welcome!</p>
);
2. Use className
instead of class
Since class
is a reserved keyword in JS, JSX uses className
.
//jsx//
<p className="message">Hello</p>
3. Use camelCase
for attributes
HTML: onclick
โ JSX: onClick
//jsx//
<button onClick={handleClick}>Click me</button>
๐งฎ Embedding Expressions in JSX
You can add JavaScript expressions inside {}
curly braces in JSX.
Example:
//jsx//
const name = "Amit";
return <h1>Hello, {name}</h1>;
You can also do calculations or call functions:
//jsx//
return <p>2 + 3 = {2 + 3}</p>;
โ
Note: You can use expressions (like variables, functions), but not statements (like if, for) inside {}
.
๐ Difference Between HTML and JSX
Feature | HTML | JSX |
Class attribute | class | className |
Inline style | String | Object |
Event handler | onclick="doThis()" | onClick={doThis} |
Close tags | Optional | Required (e.g., <img /> ) |
Comments | <!-- comment --> | {/* comment */} |
๐งโ๐ซ Real-World Analogy
Think of JSX like a mix of HTML + JS โ it looks like HTML, but it behaves like JavaScript.
For working professionals: JSX improves code readability, testing, and debugging โ very helpful in complex UIs.
โ Summary
JSX is a syntax that lets us write HTML-like code in React
It must follow special rules (like
className
, one parent, etc.)We can embed dynamic content using
{}
curly bracesJSX is not HTML, but it is very similar โ with some key differences
Ready for the next one?
If you'd like to move on to React Topic 3: Components .
follow this series in sequence wise.
๐ Stay Connected
If you found this article helpful and want to receive more such beginner-friendly and industry-relevant React notes, tutorials, and project ideas โ
๐ฉ Subscribe to our newsletter by entering your email below.
And if you're someone who wants to prepare for tech interviews while having a little fun and entertainment,
๐ฅ Donโt forget to subscribe to my YouTube channel โ Knowledge Factory 22 โ for regular content on tech concepts, career tips, and coding insights!
Stay curious. Keep building. ๐
Subscribe to my newsletter
Read articles from Payal Porwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Porwal
Payal Porwal
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: ๐ In-depth explorations of emerging technologies ๐ก Practical tutorials and how-to guides ๐งInsights on software development best practices ๐Reviews of the latest tools and frameworks ๐ก Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Letโs connect and grow together! ๐