1class Controls extends React.Component{
2 state={
3 myInterval : null,
4 time: 25*60*1000
5 }
6 countDown = () => {
7 this.setState({
8 time : this.state.time-1000,
9 })
10 }
11 startTimer = () => {
12 this.setState({myInterval : setInterval(this.countDown,1000)})
13 }
14 stopTimer = () => {
15 clearInterval(this.state.myInterval)
16 }
17 render(){
18 return(
19 <div>
20 <button onClick={this.startTimer}>Start</button>
21 <button onClick={this.stopTimer}>Stop</button>
22 {this.state.time}
23 </div>
24 )
25 }
26}
27
28
29class App extends React.Component{
30 render(){
31 return <Controls/>
32 }
33}
34
35
36
37
38
39ReactDOM.render(
40 <App />,
41 document.getElementById("react")
42);