Hi I am currently working on an app that’s setting items in localStorage then later retrieve all items. When retrieving I am parsing the object to convert it from a stringified object to an object. On doing that I am getting this error,
Error: A cross-origin error was thrown. React doesn’t have access to the actual error object in development.
I tried to look for solutions but the one that’s suggested is to clear local storage but It’s a problem because I’ll have to do that each time I press my button. Is there a fix for this.
My code:
// This function gets all items from the local storage
function getAll() {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while (i--) {
values.push(localStorage.getItem(keys[i]));
}
return values;
}
const getMissions = getAll();
// This variable stores the parsed value, ie, turning a stringified object back to an object value
const { image, missionName } = JSON.parse(getMissions);
Thank you in advance