-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
78 lines (68 loc) · 2.11 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<title>Functional Component</title>
</head>
<body>
<div id="root">Hello</div>
</body>
<script type="text/babel">
// let ele=document.createElement("h1");
// ele.innerText="Hello";
// let root=document.getElementById("root");
// console.log(ele);
// root.appendChild(ele);
//react
// let ele=React.createElement("h1",{
// children:["Hello"]
// })
// console.log(ele);
// let root = document.getElementById("root");
// ReactDOM.render(ele,root);
//jsx-> js+xml
//function component
// function Element(props){
// console.log(props);
// return(//->jsx
// <h1>Hello {props.name}</h1>
// )
// }
function Element({ name = "myName", city = "Delhi" }) {
console.log(name);
return (//->jsx
<div>
<h1>Hello {name}</h1>
<h2> from {city}</h2>
</div>
)
}
//reuse
// we can only return one elemnt inside return -> wrp the components in div or use React.Fragment
function Main() {
return (
// <div>
// <Element/>
// <Element/>
// <Element/>
// <Element/>
// <Element/>
// </div>
<React.Fragment>
<Element name="Siddhu Moosewala" city="Punjab" />
<Element />
<Element />
<Element />
<Element />
</React.Fragment>
)
}
ReactDOM.render(<Main />, document.getElementById('root'));
// ReactDOM.render(<Element />, document.getElementById('root'));
</script>
</html>