I have a serious problem when using local storage, that is, the data will be out of sync.
Here is my code section, please import it directly.
LSTest.json (7.3 KB)
Every time I run the code I get a different result than what I expected, you can check the value stored in the local storage in the state field.
But if I am using local storage directly in the browser, this should not be a problem at all.
localStorage.clear();
let value;
value = `${localStorage.value}`;
console.log(value);
localStorage.setItem('value',Math.random());
value = `${localStorage.value}`;
console.log(value);
localStorage.setItem('value',Math.random());
value = `${localStorage.value}`;
console.log(value);