mirror of
https://github.com/kay-is/react-from-zero.git
synced 2026-01-11 07:38:15 -05:00
41 lines
972 B
HTML
41 lines
972 B
HTML
<!doctype html>
|
|
|
|
<title>01 Element Factory - React From Zero</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() needs type, properties, children.
|
|
// This is less verbose than using plain object literals,
|
|
// it hides the $$type/Symbol and ref mentioned in lesson 0
|
|
var reactElement = React.createElement(
|
|
"h1",
|
|
{
|
|
className: "abc",
|
|
|
|
style: {
|
|
textAlign: "center"
|
|
},
|
|
|
|
onClick: function () {
|
|
alert("click");
|
|
}
|
|
},
|
|
"Hello, world!"
|
|
);
|
|
|
|
// The second argument is the property object,
|
|
// it has to be null if empty
|
|
var anotherElement = React.createElement(
|
|
"p",
|
|
null,
|
|
"A nice text paragraph."
|
|
);
|
|
|
|
var renderTarget = document.getElementById("app");
|
|
|
|
ReactDOM.render(reactElement, renderTarget);
|
|
</script> |