Frontend Track // Module 4

Intro to React

Say goodbye to vanilla DOM manipulation. Learn to build modern UIs with JSX and Components.

React_Intro_JSX.jsx

Preview

⚛️ Loading React...

Welcome to React! Instead of writing HTML and JS separately, we use JSX. It looks like HTML, but it's actually JavaScript in disguise.

React: JSX Power

LEVEL: FRONTEND MASTER

**JSX** (JavaScript XML) allows us to write HTML-like structures directly inside our JavaScript code. It is the heart of React's declarative nature.

1. Why JSX?

In traditional development, you keep logic (JS) and structure (HTML) in different files. React argues that they are inherently coupled. JSX lets you build **Components** that contain both.

2. Expression Embedding

You can put any valid JavaScript expression inside curly braces ``. This includes variables, function calls, or even math operations.

const element = <h1>Total: {2 + 2}</h1>;

3. The Fragment Rule

Since JSX is compiled into a single function call (`React.createElement`), it can only return **one** parent element. If you don't want to add extra DIVs to the DOM, use a **Fragment**.

A.D.A Suggestion

"In React, your UI is a function of your state. Think about what data changes, and let React handle the rest."

React Glossary

JSX

A syntax extension for JavaScript that looks like HTML.

Component

A reusable, independent piece of UI. Always starts with a Capital Letter.

Props

Short for properties, used to pass data from parent to child components.

Fragment

A ghost wrapper <></> that doesn't add nodes to the DOM.

Babel

The compiler that transforms your JSX into standard JavaScript.