user2646559 user2646559 - 5 months ago 79
React JSX Question

Local persistent storage

I have a meteor react app and I need a way to save some info locally which will also be persistent. For example, if a user save a json, I want to use that same json even if the app is closed and reopen later. I tried groundDb but it requires server side as well. I need this feature to enable each user to save info such as game level. It will be great if I can use it on the web as well and not just for native versions. Thanks!


To join the pedants, here's the proper explanation:

You should first convert your object literal into JSON using the global JSON object and its stringify method:

let data = {a: 'some', b: 'data', c: null};
let json = JSON.stringify(data);
localStorage.setItem('data', json);

When you want to retrieve the data and use it in your application, you'll need to parse the JSON back into an object literal:

let json = localStorage.getItem('data');
let data = JSON.parse(json);