forked from kay-is/react-from-zero
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path01-element-factory.html
More file actions
33 lines (21 loc) · 1.19 KB
/
01-element-factory.html
File metadata and controls
33 lines (21 loc) · 1.19 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
<!doctype html>
<title>01 Фабрика элементов - React с нуля</title>
<script src="https://unpkg.com/react@16.4.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.4.0/umd/react-dom.development.js"></script>
<div id="app"></div>
<script>
// React.createElement() требует тип, свойство, дочерние элементы.
// Его использование требует меньше кода, по сравнению с обычными объектными литералами,
// он скрывает $$type/Symbol и ref, упомянутые в нулевом уроке
var reactElement = React.createElement("h1", {
className: "abc",
style: {
textAlign: "center",
},
onClick: function () { alert("click") },
}, "Привет, Мир!")
//Второй аргумент — это объект со свойствами, он должен быть null при отсутствии свойств
var anotherElement = React.createElement("p", null, "Классный абзац текста.")
var renderTarget = document.getElementById("app")
ReactDOM.render(reactElement, renderTarget)
</script>