From the course: React Native Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with timers

Working with timers - React Native Tutorial

From the course: React Native Essential Training

Start my 1-month free trial

Working with timers

- [Instructor] Implementing a countdown to track the seconds spent playing this game is easy. We can just use a regular interval. The question is do we need to put this information on the state or not? And to answer that, we need to answer another question, which is do we need to display anything in the UI while the timer is ticking? We should probably do that. We should probably display these remaining seconds. Like you start with 10 seconds and then the counter ticks that down every second and we should display the number of remaining seconds in the UI, which means we need to put this number on the state of the game. Let's do that. We'll start with remainingSeconds. I think that's a good name. And we start with 10. Of course, we can make this configurable if we need to, if you want to make the game harder. Just like randomNumberCount, we can make this game receive another property and maybe a good name for this…

Contents