-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.html
More file actions
53 lines (45 loc) · 1.35 KB
/
State.html
File metadata and controls
53 lines (45 loc) · 1.35 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!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)
class Component extends React.Component {
// state는 객체 형태로만 제공됨
state = {
count: 0,
};
render(){
return(
<div>
<h1>{this.props.message} 이것은 class로 만든 컴포넌트 입니다.</h1>
<p>{this.state.count}</p>
</div>
);
}
componentDidMount(){
setTimeout(() => {
// this.state.count = this.state.count + 1; => 이런식으로 하면 state 안에 접근불가
this.setState({count: this.state.count + 1}); // setState 사용해야함
}, 1000);
}
static defaultProps = {
message: "기본값2"
};
}
ReactDOM.render(
<Component message="기본값 아님"/>,
document.querySelector("#root")
);
</script>
</body>
</html>