hi i am new with react native and javascript i would like to make a small countdown where you enter in the function a number and the type of countdown so now if i have selected seconds, minutes or hours in a dropdown and have in the textinput as example 10 i would enter an object like this in the function {count: ’10’, format: ‘sec’} does anyone of you have a good example what could help me with this maybe?
const startCountDown = (countdownObj) => { setCountdownRunnning(true); //countdownObj.count = 10 //countdownObj.format (sec, min, h)
}
Advertisement
Answer
At first you should read about intervals in JS: https://developer.mozilla.org/en-US/docs/Web/API/setInterval After you need read how to use setInterval in React: https://medium.com/@garethdavisrogers/using-setinterval-and-clearinterval-with-react-hooks-7fcf26dc8fdb Here you can get interval example in React Native: How to setInterval for every 5 second render with React hook useEffect in React Native app?
Good luck.