-
Notifications
You must be signed in to change notification settings - Fork 0
/
Props.html
67 lines (58 loc) · 1.6 KB
/
Props.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
63
64
65
66
67
<!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)
// 1. function Component
// props => {message: '안녕하세요!!!'}
function Component(props) {
return (
<div>
<h1>{props.message} 이것은 function으로 만든 컴포넌트 입니다.</h1>
</div>
);
}
// 2. class Component
class Component extends React.Component {
render(){
return(
<div>
<h1>{this.props.message} 이것은 class로 만든 컴포넌트 입니다.</h1>
</div>
);
}
}
// 3. 기본값을 사용하는 방법
Component.defaultProps = {
message: "기본값",
};
// 4. 기본값을 사용하는 방법2
class Component extends React.Component {
render(){
return(
<div>
<h1>{this.props.message} 이것은 class로 만든 컴포넌트 입니다.</h1>
</div>
);
}
static defaultProps = {
message: "기본값2"
}
}
ReactDOM.render(
<Component message="안녕하세요!"/>,
document.querySelector("#root")
);
</script>
</body>
</html>