-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
executable file
·65 lines (55 loc) · 1.46 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<script src="../build/react.js"></script>
<script src="../build/react-dom.js"></script>
<script src="../build/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
class Input extends React.Component {
handleChange(event){
this.props.changeNumber(event.target.value);
}
render () {
return (
<div>
<input type='number' onChange={(e)=>{this.handleChange(e)}} />
</div>
)
}
}
class PercentageShower extends React.Component {
render () {
return (
<div>
{(this.props.value*100).toFixed(2)}%
</div>
)
}
}
class PercentageApp extends React.Component {
constructor(){
super();
this.state={value: 0};
}
changeNumber(number){
this.setState({value: number});
}
render () {
return (
<div>
<Input changeNumber={this.changeNumber.bind(this)}></Input>
<PercentageShower value={this.state.value}></PercentageShower>
</div>
)
}
}
ReactDOM.render(
<PercentageApp></PercentageApp>,
document.getElementById('example')
);
</script>
</body>
</html>