onclick start and stop the count react
class Controls extends React.Component{
state={
myInterval : null,
time: 25*60*1000
}
countDown = () => {
this.setState({
time : this.state.time-1000,
})
}
startTimer = () => {
this.setState({myInterval : setInterval(this.countDown,1000)})
}
stopTimer = () => {
clearInterval(this.state.myInterval)
}
render(){
return(
<div>
<button onClick={this.startTimer}>Start</button>
<button onClick={this.stopTimer}>Stop</button>
{this.state.time}
</div>
)
}
}
class App extends React.Component{
render(){
return <Controls/>
}
}
ReactDOM.render(
<App />,
document.getElementById("react")
);
Also in JavaScript:
- localstorage javascript
- what is angularjs
- vuex-module-decorators access other state
- focus on input field vuejs event
- javascript queryselector
- express jwt
- javascript uncheck radio button
- mutable array methods in javascript
- javascript create svg
- what is react native
- console.log clear screen
- change true to false js
- js hangman with repeated characters
- get first element by class name jquery
- javascript array vs object
- jQuery check a radio button
- core.js:6228 ERROR TypeError: Cannot read property 'image' of undefined
- take a screen shot of a image within a div using js
- okay
- javascript change attribute
- fibanachi
- discord js people in voice channel
- template literals javascript
- javascript modal