JavaScript Local Storage with Expiration local storage with react,local storage with jquery,local storage

There's no built-in way to expire values in storage. One solution is to store a timestamp, then in each visit compare the stored time (if there is one) against the local time to determine if the value has expired. Example:

const expirationDuration = 1000 * 60 * 60 * 12; // 12 hours

const prevAccepted = localStorage.getItem("accepted");
const currentTime = new Date().getTime();

const notAccepted = prevAccepted == undefined;
const prevAcceptedExpired = prevAccepted != undefined && currentTime - prevAccepted > expirationDuration;
if (notAccepted || prevAcceptedExpired) {
  alert("Disclaimer: ...");
  localStorage.setItem("accepted", currentTime);
}
Answer:1

I've a function to update the DB rows one by one with Parse's promise exports.update = function (items, successHandler, errorHandler) { Parse.Cloud.useMasterKey(); var Item = Parse.Object....

I've a function to update the DB rows one by one with Parse's promise exports.update = function (items, successHandler, errorHandler) { Parse.Cloud.useMasterKey(); var Item = Parse.Object....

  1. nested promise in node js
  2. nested promise in javascript
  3. nested promise in angularjs
  4. nested promise in js

Is there a shorter more efficient way of doing this? it seems a little hefty and I just want to know if it can be condensed? var y = [] for(let i=0;i < word.length;++i){ if(word[i] == "A"||...

Is there a shorter more efficient way of doing this? it seems a little hefty and I just want to know if it can be condensed? var y = [] for(let i=0;i < word.length;++i){ if(word[i] == "A"||...

In my app I have several classes which are used to create XML strings. Each class has a few methods that take some arguments and return a string. I want to specify this limitation so that methods with ...

In my app I have several classes which are used to create XML strings. Each class has a few methods that take some arguments and return a string. I want to specify this limitation so that methods with ...

In my SPA I am using axios to make requests to the API. I currently use axios request interceptors to add auth headers to requests but I also wanted to use them to catch 401 errors and remove the ...

In my SPA I am using axios to make requests to the API. I currently use axios request interceptors to add auth headers to requests but I also wanted to use them to catch 401 errors and remove the ...

  1. axios catch request