Answer the question
In order to leave comments, you need to log in
Constant time tracking?
Good time of the day, please tell me how you can constantly track the time, I have half of the application tied to time, now I just have
const time = new Date (), but the problem is that the time is written to the constant at the entrance and is not updated further, you need keep an eye on him
Answer the question
In order to leave comments, you need to log in
I think you should use setInterval
const [dateTime, setDateTime] = useState(new Date());
useEffect(() => {
const id = setInterval(() => setDateTime(new Date()), 1000);
return () => {
clearInterval(id);
}
}, []);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question