-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApp.js
More file actions
103 lines (87 loc) · 2.71 KB
/
App.js
File metadata and controls
103 lines (87 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 🎬 Ep: 2 — Understanding How Bundlers Like Parcel Work Under the Hood
/*
🔧 Parcel Features:
- Zero Configuration
- HMR (Hot Module Replacement): Uses C++-based File Watcher to update files on changes.
- Caching (During Development)
- Image Optimization
- Code Compression
- Differential Bundling (Supports older browsers)
- HTTPS Support for Dev Server (e.g. `npx parcel index.html --https`)
- Dynamic Port Handling (auto changes if port is occupied)
- Consistent Hashing Algorithm
- Tree Shaking (removes unused code)
- Error Diagnostics
- Code Cleaning (e.g. removing console.log in builds)
- Supports Dev & Production Builds
- Super Fast Build Algorithm
- Transitive Dependencies (dependencies of dependencies)
*/
/*
📝 HTML Code Converted into React.createElement Format:
<div id="parent">
<div id="child">
<h1>Hello from React</h1>
<h2>Subheading</h2>
</div>
</div>
*/
import React from "react";
import ReactDOM from "react-dom/client";
// 👇 React.createElement usage (Behind-the-Scenes React)
const parent = React.createElement(
"div",
{ id: "parent" },
[
React.createElement("h1", {}, "Hello from React parent"),
React.createElement(
"div",
{ id: "child" },
[
React.createElement("h1", {}, "Hello from React"),
React.createElement("h2", {}, "Subheading")
]
),
React.createElement(
"div",
{ id: "2" },
[
React.createElement("h1", {}, "Hello from React child 2"),
React.createElement("h2", {}, "Subheading 2")
]
)
]
);
// Root creation
const root = ReactDOM.createRoot(document.getElementById("root"));
// root.render(parent); // Render createElement version
// 🎬 Ep: 3 — Laying the Foundation of React
// ✅ JSX Element Example
const jsxHeading = <h1>Hello from React using JSX</h1>;
// root.render(jsxHeading); // Render JSX version
// * interview Tip: Difference between JSX and React.createElement
// - JSX is syntactic sugar for React.createElement()
// - JSX gets compiled by Babel to React.createElement() calls
/*
📘 React Components Overview:
- Class Components (older way)
- Functional Components (modern way)
*/
// ✅ Functional Component Syntax Example 1 (with return)
const TitleComponent = () => {
return <h1>React Title Component</h1>;
};
// ✅ Functional Component Syntax Example 2 (without return - implicit)
const HeadingComponent = () => (
<div id="container">
{/* Different ways to use components:
- <TitleComponent />
- <TitleComponent></TitleComponent>
- TitleComponent()
*/}
<TitleComponent />
<p className="heading">React Functional Component</p>
</div>
);
// 📦 Rendering our Final Component
root.render(<HeadingComponent />);