I have an application on a react. It has two modules: one that sets true
value in localStorage
, the second that runs the code and then sets false
value to localStorage
I am trying to check as follows:
localStorage.setItem('update', false);
const checkUpdate = () => {
if (localStorage.getItem('update') == 'true') {
localStorage.setItem('update', false)
alert('SUCCESFUL')
return true
} else {
return false
}
}
if (checkUpdate() == true) {
console.log('OK')
} else {
setTimeout(checkUpdate(), 2000)
}
It just does not work, and I can’t understand what my mistake is