-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathApp.js
108 lines (102 loc) · 2.17 KB
/
App.js
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
104
105
106
107
108
// ## Namaste React Course by Akshay Saini
// # Chapter 03 - Laying the Foundation
/*
* This are the feature of Parcel
* Created A Server
* HMR - Hot Module Replacement
* File Watcher algorithm - C++
* BUNDLING
* MINIFY
* Cleaning our Code
* Dev abd Production Build
* Super Fast build algorithm
* Image Optimization
* Caching while development
* Compression
* Compatible with older version of browser
* HTTPS on dev
* port Number
* Consistent Hashing Algorithm
* Zero Config
* Tree shaking
*
*
* Transitive Dependencies
*/
// imported react and reactdom from nodemodule folder
// import {React, createElement as ce} from 'react';
import React from "react";
import ReactDOM from "react-dom/client";
// Create Header element like navbar using createElement
/*
*
<div class="header">
<h1>Title</h1>
<ul>
<li>Home</li>
<li>About Us</li>
</ul>
*
*
*/
// const heading = ce(
// "div",
// {
// className: "header",
// key: "header",
// },
// [ce(
// "h1",
// {
// key: "Title",
// },
// "Title"), ce(
// "ul",
// {
// key: "ul",
// },
// [ce(
// "li",
// {
// key: "Home",
// },
// "Home"),ce(
// "li",
// {
// key: "About Us",
// },
// "About Us")])]
// )
// create header element using JSX
// JSX => React.createElement => Object => HTML (DOM) (babel does all the conversion)
const heading = (
<h1 id="h1" key="h1">
This is JSX
</h1>
);
// React Component
// Functional component - new way of writing component
// Class component - old way of writing component
// Title component is functional component
const Title = () => {
return (
<h1 id="title" key="title">Namaste React</h1>
)
}
// Header component is functional component
const HeaderComponent = function (){
return (
<div>
<Title/>
{/* we can also use <Title()> */}
{/* we can also use <Title></Title> */}
{console.log(10)}
<h1>Namaste React Functional component</h1>
<h2>This is h2 tag</h2>
</div>
)
}
// create root using createRoot
const root = ReactDOM.createRoot(document.getElementById("root"));
// passing react element inside root
root.render(<HeaderComponent/>);