<!DOCTYPE html>
<html>
<body>
<div id="root"></div>
</body>
<script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
<script>
const root = document.getElementById("root");
const h3 = React.createElement(
"h3",
{
onMouseEnter: () => console.log("mouse enter")
},
"Hello I'm a span"
);
const btn = React.createElement(
"button",
{
onClick: () => console.log("i'm clicked"),
},
"Click me"
);
const contaner = React.createElement("div", null, [h3, btn]);
ReactDOM.render(contaner, root); ```React element들을 root div 안에서 보여줘라```
</script>
</html>
React JS, ReactDOM 코드를 import
const h3 = React.createElement,
const btn = React.createElement,
const contaner = React.createElement
바닐라 JS는 element에 각각 event listener를 달아야 함. React는 event listener를 등록하고 계속 사용할 수 있다. onClick(on~) 등의 event가 이미 등록되어 있는 상태
JSX는 자바스크립트의 확장버전, 객체를 표현한다
<!DOCTYPE html>
<html>
<body>
<div id="root"></div>
</body>
<script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
const root = document.getElementById("root");
const Title = () => (
<h3 id="title" onMouseEnter={() => console.log("mouse enter")}>
Hello I'm a title
</h3>
);
const Button = () => (
<button
style={{
backgroundColor: "tomato",
}}
onClick={() => console.log("im clicked")}
>
Click me
</button>
);
const Contaner = (
<div>
<Title />
<Button />
</div>
);
ReactDOM.render(Contaner, root);
</script>
</html>