简体   繁体   中英

How can i set a fucntion related to a button to start , pause Interval according to certain condition in REACT using hooks?

would please help me find a solution to my problem, here is the codepen code to make things easier for you [https://codepen.io/darkuni/pen/oNZEKrp?editors=0010][1].

I have tried to read other's code, documentation watch videos but i couldn't get out with any solution (please no toxic comments).

i guess from seeing my code, you can tell that i am trying to start an Interval to update the timer value, and stop it when it reaches "00:00".

Thanks in advance

First of all, don't ever use the setInterval and setTimeOut in a function because it can cause an endless loop, instead use them in useEffect or componentDidMount and you should always clear them (line 48 of the sandbox that i'm sharing you) go to this link: https://codesandbox.io/s/determined-zhukovsky-609rj?file=/src/App.js you can see the changes i made to your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM