-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
48 lines (42 loc) · 1.07 KB
/
sample.js
File metadata and controls
48 lines (42 loc) · 1.07 KB
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
/**
* Created by ptmbr012 on 2016/01/29.
*/
var CountDown = React.createClass({
displayName: 'CountDown',
getInitialState: function(){
return {
timeRemaining: 10
}
},
tick: function(){
if (this.state.timeRemaining == 1){
this.setState({timeRemaining: 'Boom'})
clearInterval(this.interval)
} else {
this.setState({timeRemaining: this.state.timeRemaining - 1})
}
},
componentDidMount: function(){
this.interval = setInterval(this.tick, 1000);
},
render: function () {
if (this.state.timeRemaining === 'Boom'){
return (<p><img src="images/firework_icon.gif"/></p>);
} else {
return (<p id="txt">{this.state.timeRemaining}</p>);
}
}
});
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
Hello, world! I am a CommentBox.
</div>
);
}
});
ReactDOM.render(
<CountDown />,
document.getElementById('content')
);