onclick start and stop the count react code example

Example: 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(
            
{this.state.time}
) } } class App extends React.Component{ render(){ return } } ReactDOM.render( , document.getElementById("react") );

Tags:

Misc Example