-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.js
62 lines (60 loc) · 1.81 KB
/
basic.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
import React from "react";
import ReactDOM from "react-dom/client";
const heading = React.createElement(
"h1",
{ id: "heading", class: "heading" },
"Hello"
);
//head or parent or parent1 is a ReactElement nothing but return jsobject => (Browsers will understan)
//nested tags
{
/*
<div id='parent'>
<div id='child'>
<h1>I am a h1 tag</h1>
<h2>I am a h2 tag</h2>
</div>
</div>;
if we have multiple childern we need to pass in array[h1, h2]
*/
}
const parent = React.createElement(
"div",
{ id: "parent" },
React.createElement("div", { id: "child" }, [
React.createElement("h1", { key: "h1" }, "I am a h1 tag"),
React.createElement("h2", { key: "h2" }, "I am a h2 tag"),
])
);
{
/* <div id="parent">
<div id="child">
<h1>I am a h1 tag</h1>
<h2>I am a h2 tag</h2>
</div>
<div id="child">
<h1>I am a h1 tag</h1>
<h2>I am a h2 tag</h2>
</div>
</div>; */
}
const parent1 = React.createElement("div", { id: "parent" }, [
React.createElement("div", { id: "child" }, [
React.createElement("h1", { key: "h1" }, "I am Tejesh tag"),
React.createElement("h2", { key: "h2" }, "I am a h2 tag"),
]),
React.createElement("div", { id: "child" }, [
React.createElement("h1", { key: "h11" }, "I am a h1 tag"),
React.createElement("h2", { key: "h22" }, "I am a h2 tag"),
]),
]);
console.log(parent1); // it return the javascript object
//creaRoot is for adding childs to it
const root = ReactDOM.createRoot(document.getElementById("root"));
//render method will help convert react element into html and display in browser
root.render(parent1);
//what ever inside in the root(attribute in html) will be replaced not append
//library where we want just apply
//React will do as it is
//we have written two div one head and root
// but our react is applied only for root that is library