I want to calculate the duration of a ticket created when the app is in offline and display a toast message to sync the data within 24Hrs in the offline mode itself.
static getDerivedStateFromProps(props, state) {
if (!props.isOnline && !props.isInternetReachable) {
let curr_time = moment().format();
let offlineTicketCreatedTime = state.offlineNewTicketList.length > 0
? moment(state.offlineNewTicketList[0].Created).format()
: 0;
let difference = parseFloat(
moment
.duration(
moment.utc(curr_time).diff(moment(offlineTicketCreatedTime))
)
.asSeconds()
);
if (difference > 1400) {
alert("Sync now!!!");
}
}
return null; }
But this works only one time. I want to calculate the time in background even when I'm in other screens in offline mode. I want to run this calculation as a timer. And when the time is 23Hrs 50min a toast needs to be shown.