-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.html
68 lines (56 loc) · 1.75 KB
/
counter.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
68
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Bloc</title>
</head>
<body>
<div id="app"></div>
<script src="https://fb.me/react-15.0.0.js"></script>
<script src="https://fb.me/react-dom-15.0.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script type="text/babel">
class Counter extends React.Component {
constructor(props){
super(props);
this.state = {
number: 1
}
}
increment(event) {
this.setState({
number: this.state.number + 1
})
}
decrement(event) {
this.setState({
number: Math.max(1, this.state.number - 1)
})
}
render() {
return (
<div>
<img src={this.props.image} alt="Bloc Logo"/>
<h2>Current program: {this.props.label}</h2>
<h3>Current week: {this.state.number}</h3>
<button onClick={this.increment.bind(this)}>Increment</button>
<button onClick={this.decrement.bind(this)}>Decrement</button>
<p>Current Date: {this.props.date.toLocaleDateString()}</p>
</div>
);
}
}
const info = {
date: new Date(),
image: 'https://avatars0.githubusercontent.com/u/1441485?v=4&s=280',
}
Counter.defaultProps = {
label: "Web Developer Track"
}
ReactDOM.render(
<Counter
date={info.date}
image={info.image}/>,document.getElementById('app')
);
</script>
</body>
</html>