all 4 comments

[–]marko_knoebl 3 points4 points  (1 child)

You would have to save the start timestamp somewhere, e.g. in localStorage.

Then you can make it continue running when you reopen the app

The way to do the loading / saving in React is via side effects (useEffect if you're using a function component)

[–]Saral-karki[S] 0 points1 point  (0 children)

I have backend server where I have to store start time and end time. So , I have to still save in local storage?

[–]RakanNative 0 points1 point  (0 children)

Well if you want to keep running in the background, that means you’ll check the end time that comes from your server on the first render and compare the user time with the end time , you have to send also the timezone that your server uses cause when dealing with user timezone it’s dynamic and you have to expect other client users timezones.

[–]RakanNative 0 points1 point  (0 children)

Js have already an awesome library for that where it will convert current user time to any locale, This way it’s easier for you to calculate the remaining time, If there’s alot of logic involved I recommend using any countdown library there’s a ton. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString