Skip to main content

Command Palette

Search for a command to run...

๐Ÿง  Introduction to React & โš›๏ธ JSX (JavaScript XML)

Updated
โ€ข6 min readโ€ขView as Markdown
๐Ÿง  Introduction to React  & โš›๏ธ JSX (JavaScript XML)
P
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! ๐ŸŒŸ

๐Ÿง  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:

FeatureJavaScript / jQueryReact
Page ReloadFull page reload on actionsNo reload โ€” fast updates
Code StructureUnstructured, messy for big appsComponent-based & organized
ReusabilityDifficultEasy using components
PerformanceSlower in large appsFast with Virtual DOM
Data FlowComplicatedOne-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

2. Install VS Code (Code Editor)


๐Ÿš€ Create First React App

We use a tool called Create React App (CRA) to quickly set up a basic React project.

๐Ÿ‘‰ Steps:

  1. Open terminal or command prompt

  2. Type this:

npx create-react-app my-first-app
  1. It will take a few minutes to set up

  2. Go to the folder:

cd my-first-app
  1. 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 file

  • src/: Where your React code lives (JSX, components, etc.)

  • App.js: Main component shown first

  • index.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

FeatureHTMLJSX
Class attributeclassclassName
Inline styleStringObject
Event handleronclick="doThis()"onClick={doThis}
Close tagsOptionalRequired (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 braces

  • JSX 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. ๐Ÿš€

React Deep Dive: From Fundamentals to Real Projects

Part 1 of 11

A beginner-friendly React series that covers JSX, components, routing, APIs, and state managementโ€”everything you need to build real-world apps and become job-ready as a React developer. ๐Ÿ“บ Subscribe now: https://www.youtube.com/@KnowledgeFactory22

Up next

โš›๏ธ React Components (Topic 3)

โœ… What is a Component in React? A component is like a reusable building block in React.Just like a house is made of bricks, a React app is made of components. Example: A website may have a Header, Footer, Sidebar, and ProductCard โ€” all can be separa...

More from this blog

T

Technologies: Tools & Tips | Expert Guides on Latest Tech Tools

126 posts