-
Notifications
You must be signed in to change notification settings - Fork 700
/
24-lifting-and-colocating.html
49 lines (45 loc) · 1.26 KB
/
24-lifting-and-colocating.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
<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 Name({name, onNameChange}) {
return (
<div>
<label>Name: </label>
<input value={name} onChange={onNameChange} />
</div>
)
}
function FavoriteAnimal() {
const [animal, setAnimal] = React.useState('')
return (
<div>
<label>Favorite Animal: </label>
<input
value={animal}
onChange={event => setAnimal(event.target.value)}
/>
</div>
)
}
function Display({name}) {
return <div>{`Hey ${name}, you are great!`}</div>
}
function App() {
const [name, setName] = React.useState('')
return (
<form>
<Name
name={name}
onNameChange={event => setName(event.target.value)}
/>
<FavoriteAnimal />
<Display name={name} />
</form>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
</script>
</body>