Home > Software design >  Storing a class in local storage?
Storing a class in local storage?

Time:07-22

Please tell me, I am working with the ual-anchor library for authorization, as well as with ual-plainjs-renderer for rendering a modal authorization window. My problem is to store an instance of the UALJS class in local storage (or somewhere else) so that I can access this class even after a page reload.

CodePudding user response:

You are limited to store string key/value pairs in localstorage. The only option is to use JSON.stringify() and JSON.parse(obj)

checkout this thread:

https://stackoverflow.com/a/2010948/12165605

CodePudding user response:

Try using localStorage like this--

localStorage.setItem("class", JSON.stringify(class));
let class = JSON.parse(localStorage.getItem("class"))
localStorage.removeItem("class");
  • Related