How to simultaneously work with cookies and DB?

Good time of day.

Suppose DB contains the tasks with a deadline. Need something(no matter how) to mark those tasks in the database when the expiry date has passed, i.e., when the task became overdue.

Without a database, I just did so(if you can't do that, then please correct me)

componentWillMount() {
 setInterval(() => {
 const newTodos = this.markExpiredTodos();
 bake_cookie('todos', newTodos); // rewrite cookies
 }, 10000);
markExpiredTodos() {
 const allTodos = read_cookie('todos'); // get the current data from cookies
 allTodos.forEach((todo) => {
 // check the dates and mark
 return allTodos;

Now there are databases and APIs.
componentWillMount() {
 this.interval = setInterval(() => {
 const newTodos = this.markExpiredTodos();
 this.props.saveTodos(newTodos); // send the query to the database instead of working with cookies
 }, 10000);

How can I improve? Also work with cookies and put another setInterval to send a request to the database or to make queries in the database? And maybe even to work with the server time? Or is there some other way?
June 8th 19 at 17:06
1 answer
June 8th 19 at 17:08
You not from that side approach the task.
Write to DB timestamp deadLineDate, by creation date or status.
Register. To determine the status of what? Status overdue if a job using the created date? Question all else the same. - Ole47 commented on June 8th 19 at 17:11
according to timestamp and time on task. Simple arithmetic. Received from the database task was calculated expired or not. If must be nice to update state on the client, for non-expired run the setTimeout, in this case just the local guys are changing the status without a record in the database. - Lenny.Botsfo commented on June 8th 19 at 17:14
you read the question? I'm not asking how to determine that the task is overdue. I ask at what stage to keep it all in the database. - Ole47 commented on June 8th 19 at 17:17
as you can see , this information generally can not be stored in the database. It is easier to calculate. Read the question. You not from that side approach the task. - Lenny.Botsfo commented on June 8th 19 at 17:20
not arguing, maybe I don't understand something. I have a question due to the fact that, if the interval setintervala to perform an action on the task, e.g. mark it complete and send the appropriate query to the database, then the client at the end of this period setintervala task again becomes incomplete. Probably, I incorrectly organized work with the state. In any case, thanks for your answers. - Ole47 commented on June 8th 19 at 17:23
look in the schema which you wanted to realize, there is no guarantee that the client will not have problems with Internet connection and a request for change of status will definitely come, as there is no guarantee that he just closes the tab with the counters.
I've slightly revised the task and you only need a timestamp deadLineDate.
You are downloading the task and if the task is closed, do nothing if not closed see deadlineDate and compare with the current date and time, if deadLineDate has already passed, ie the current timestamp more mark her as delinquent, if not include in the client timer. The timer is needed only to refresh the display already loaded tasks. But you can still countdown show if you want. There is no need to use setIntervaland setTimeout, and clear have if the task is to change the status to completed. For this illsuited clearTimeout. - Lenny.Botsfo commented on June 8th 19 at 17:26

Find more questions by tags ReduxReactDatabases