I've got a react application and I want to display the time and date with the time updating every minute as it should. I wrote this code but if I leave the app running for an extended period of time I eventually get a crash that tells me the memory has been exceeded.
If there is a better way to do this I'd love some guidance. Thanks.
let currentDate = new Date();
setInterval(() => {
currentDate = new Date();
setDate({
time: currentDate.toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
}),
date: currentDate.toDateString().slice(3),
});
}, 60000);