I'm trying to get data from localStorage, but my whole app becomes a blank screen with the data I'm trying to retrieve at the top of it.
I was reading online that I should add return false; to the function where I'm getting the data, but it doesn't help.
Code:
window.localStorage.setItem('test',
JSON.stringify({ scoreId: window.scoreId, streak: 0, testMe: 'testing, testing'})
);
const retrieveStreak = () => {
const test = JSON.parse(window.localStorage.getItem('test'));
const testStreak = document.getElementById('root').textContent = test.testMe;
console.log(testStreak);
return false;
}
Otherwise the data is saving successfully, and when retrieving it I also get it printed out in console.log, but the issue is that my whole app goes blank.
Deleted
document.getElementById('root').textContent =
from the code and now it works as expected
Thank Quentin for the tip
window.localStorage.setItem('test',
JSON.stringify({ scoreId: window.scoreId, streak: 0, testMe: 'testing, testing'})
);
const retrieveStreak = () => {
const test = JSON.parse(window.localStorage.getItem('test'));
const testStreak = document.getElementById('root').textContent = test.testMe;
console.log(testStreak);
return false;
}