Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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")
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: reactive forms angular conditional disabling 
Javascript :: js resize div with mouse 
Javascript :: heroku node js h21 backend connection refused 
Javascript :: prevent htmp injection in jsp 
Javascript :: querySelector a slot vuejs 
Javascript :: react cleanup meas 
Javascript :: devexpress winforms get readonly colour for current themes 
Javascript :: site completo com ajax jquery 
Javascript :: react s.a.createElement("div",{className:"d-none d-lg-flex flex-content"},s.a.createElement(u.a.Body,{noScroll:!0} 
Javascript :: is nodejs code visible client side 
Javascript :: make directive to return dropdown values angular 
Javascript :: click and copy jquery dynamic content 
Javascript :: diynamic time vue js 
Javascript :: js map vs react js map 
Javascript :: sequelize log Special methods 
Javascript :: ismodified function 
Javascript :: {backgroundimage: `url("${require(`../../assets/images/${post.image}`)}")`}; 
Javascript :: get random hsl value, javascript 
Javascript :: normalizePort 
Javascript :: Decodes a string of data which has been encoded using base-64 encoding - Nodejs 
Javascript :: stop playing music when page is closed react 
Javascript :: Diff is not a function in Moment.js 
Javascript :: how to send json data to server in android using volley 
Javascript :: javascript accessing this in callback 
Javascript :: Checking equality with Promise.resolve vs async return 
Javascript :: instafeeed.js pulls back unknown for image file 
Javascript :: google auto complete not show on modal 
Javascript :: removing element at index without changing the original array 
Javascript :: how to replace all words in javascript in hindi 
Javascript :: order by ascending descending in angular 6 on click of button 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =