forked from kentcdodds/beginners-guide-to-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
19-basic-forms.html
27 lines (25 loc) · 898 Bytes
/
19-basic-forms.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
<body>
<div id="root"></div>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/[email protected]/babel.js"></script>
<script type="text/babel">
function UsernameForm() {
function handleSubmit(event) {
event.preventDefault()
const username = event.target.elements.usernameInput.value
alert(`You entered: ${username}`)
}
return (
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="usernameInput">Username:</label>
<input id="usernameInput" type="text" />
</div>
<button type="submit">Submit</button>
</form>
)
}
ReactDOM.render(<UsernameForm />, document.getElementById('root'))
</script>
</body>