-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventHandling(함수분리).html
62 lines (54 loc) · 1.55 KB
/
eventHandling(함수분리).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
<!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">
<title>Example</title>
</head>
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script type="text/javascript">
console.log(React);
console.log(ReactDOM)
// function Component(){
// return (
// <div>
// <button
// onClick={() => {
// console.log("clicked");
// }}
// >
// 클릭
// </button>
// </div>
// );
// }
// 값이 바뀌게 하려면 다시 랜더 시켜야 하기 때문에 위에 코드를 다시 랜더 시켜준다.
class Component extends React.Component {
state = {
count: 0,
};
render() {
return (
<div>
<p>{this.state.count}</p>
<button onclick={this.click}>클릭</button>
</div>
);
}
// 밖에 따로 만들어서 넣어주기(arrow function으로 만들어서 this 알도록 해줌)
click = () => {
console.log("clicked");
this.setState(state => ({
...state,
count: state.count + 1
}));
}
}
ReactDOM.render(<Component />, document.querySelector("root"));
</script>
</body>
</html>