-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world.html
63 lines (51 loc) · 2.03 KB
/
hello_world.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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- Core react library -->
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<!-- React DOM helps us add our React Components to the DOM -->
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<!-- BabelJS is needed to transpile JSX to the JS that browser can understand-->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Your custom script here -->
</head>
<body>
<div id="app"></div>
<script type="text/babel">
class App extends React.Component {
state = {
name: "a guy has no name!",
age: "just a number!"
}
handleChange = (event) => {
this.setState( {
name: event.target.value
}
);
}
// use arrow functions so that component reference as `this` keyword is available within the function
handleSubmit = (event) => {
// defautl submit behavior is to refresh the page and we don't want that
event.preventDefault();
console.log(this.state.name + " submitted the form");
}
render() {
return(
<div className="app-content">
<h1>Hello { this.state.name }</h1>
<form onSubmit={ this.handleSubmit }>
<input type="text" onChange= { this.handleChange } />
<button>Submit</button>
</form>
</div>
);
}
}
// tell what to render and where
ReactDOM.render(<App />, document.getElementById("app"));
</script>
</body>
</html>