I have a React state variable for an array of todos, each of which is a javascript object with a "daysRemaining" property. At the start of every day (12 AM), I want to iterate through this array and decrement the keys by 1. Right now I have no clue how to do this as I am storing this array in localStorage and the only time the node server runs is when I run npm start. If I were to host this application for many users and have a dedicated server running 24/7 how would I accomplish this daily update?
2
Answers
Your state variable should be listening or fetched from a backend, then your backend should have a cronjob to update the keys.
You can achieve this by setup cronjob and socket.io by this whenever cron job hits at midnight you have to call socket on your backend and receive the signals on your frontend and then you can update the state
Backend
Front end