Let's say, you're implementing a feature that functions based on the browser's storage, such as local storage or session storage.
You manipulate the storage programmaticallybased on the feature's events and use that data in the storage to do something. However, you might run into an issue which you're not getting the correct storage data - in other words - you're getting outdated information.
But why? Even though you've been listening to the Storage event!
javascript
const handleStorageChange = event => {
if (event.key ==='myKey')) {
// DO SOMETHING
}
}
window.addEventListener('storage', handleStorageChange)
Listen to "storage" event
It is because of
“The storage event of the Window interface fires when a storage area (localStorage or sessionStorage) has been modified in the context of another document.