⚛️ JSX & React Project Structure
This topic explains how React writes UI code and how React apps are organized.
🧩 What is JSX ❓
JSX Meaning JSX = JavaScript XML
👉 Allows writing HTML inside JavaScript. Simple meaning
- HTML-like syntax inside JS
- Makes UI code easier to write
🧠 Why JSX Exists
Without JSX (pure JS)
React.createElement("h1", null, "Hello");With JSX (easy)
<h1>Hello</h1>✅ Cleaner ✅ Readable ✅ Faster development
✍️ Basic JSX Example
function App() {
return <h1>Hello React</h1>;
}
✔ Looks like HTML ✔ Actually converted to JavaScript⚠️ JSX Rules (Very Important)
1. Return only one parent element
❌ Wrong
return ( <h1>Hello</h1> <p>Welcome</p> );✅ Correct
return ( <div> <h1>Hello</h1> <p>Welcome</p> </div> );2. Use className instead of class
<div className="box"></div>Because
class is reserved in JavaScript.3. Close all tags
<img src="logo.png" /><input />4. JavaScript inside { }
const name = "Deepak";✔ Dynamic content rendering
return <h1>Hello {name}</h1>;
🔄 JSX Expressions
You can use:
- Variables
- Functions
- Conditions
Example
let age = 20;return <p>{age >= 18 ? "Adult" : "Minor"}</p>;📁 React Project Structure
When you create a React app, files follow a structure.
🗂️ Typical React Folder Structure
my-app/📦 Important Folders Explained
├── node_modules/
├── public/
├── src/
│ ├── App.js
│ ├── index.js
│ ├── components/
│ └── styles/
├── package.json
📁 public/
- Static files
- index.html
- Images
- Favicon
Browser loads this first.
📁 src/ (Most Important)
- Main application code
- Components
- Styles
- Logic
You work here daily.
📄 App.js
- Main component
- Controls UI structure
- Parent of all components
📄 index.js
- Entry point of app
- Renders App into DOM
Example idea
ReactDOM.render(<App />, document.getElementById("root"));📄 package.json
- Project dependencies
- Scripts
- Version info
🧠 How React App Runs (Flow)
1️⃣ index.html loads
2️⃣ index.js runs
3️⃣ App component renders
4️⃣ UI appears
⚠️ Common Beginner Mistakes
- Multiple parent elements in JSX
- Using
class instead of className- Forgetting to close tags
- Editing files outside
src🧪 Mini Practice Task
- Create JSX heading showing your name
- Use variable inside JSX
- Create simple component folder structure
- Create a new component and use inside App
✅ Mini Practice Task – Solution ⚛️
🟦 1️⃣ Create JSX heading showing your name
👉 Inside
App.jsfunction App() {
return <h1>My name is Deepak</h1>;
}
export default App;
✔ JSX looks like HTML✔ React renders heading on screen
🔤 2️⃣ Use variable inside JSX
👉 JavaScript values go inside
{ }function App() {
const name = "Deepak";
return <h1>Hello {name}</h1>;
}
export default App;
✔ Dynamic content rendering✔ React updates if value changes
📁 3️⃣ Create simple component folder structure
Inside
src/ folder create:src/✔
├── App.js
├── index.js
└── components/
└── Header.js
components/ keeps reusable UI code✔ Better project organization
🧩 4️⃣ Create new component and use inside App
✅ Step 1: Create
Header.js inside components/function Header() {
return <h2>Welcome to My Website</h2>;
}
export default Header;
✅ Step 2: Use component in App.jsimport Header from "./components/Header";✔ Component reused
function App() {
return (
<div>
<Header />
<h1>Hello React</h1>
</div>
);
}
export default App;
✔ Clean UI structure
🧠 What you learned
✅ Writing JSX
✅ Using variables inside JSX
✅ Organizing React project
✅ Creating reusable components
Double Tap ♥️ For More