Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
Create a react state that changes with time

I am creating a game with react and i want to add a chronometre feature to track time but i tried to use settimeout and it failed bcs every render the settimeout recall and i tried setinterval but failed also can anyone suggest me a way to to this the game is a tenzies game

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are using a functional component then you are going to have to set an interval constant in the useEffect() hook:

useEffect(() => {
  const interval = setInterval(() => {
    //code inside here will run every second
  }, 1000); //change the 1000 to however many miliseconds you want between execution
  return () => clearInterval(interval);
}, []);

This code will run whatever is in the setInterval body every second, but this amount can be changed (change the '1000'). The interval will then be cleared. Note that this interval will stop counting when the component is unmounted

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!